/**
 * Created by ASUS on 2017/5/24.
 */
var mappingRule=''
var rmsRollRoom=''
var rmsRoll=''
var file
var fileRule
var val
var fileContent = ''
Array.prototype.removeDuplicate= function(){//去重
    var res = [];
    var json = {};
    for(var i = 0; i < this.length; i++){
        if(!json[this[i]]){
            res.push(this[i]);
            json[this[i]] = 1;
        }
    }
    return res;
};
Array.prototype.indexOf = function(val) {//查找
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
    }
    return -1;
};
Array.prototype.remove = function(val) {//删除
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};





var user_id='';
var dept_id='';
var priv_id='';
var form,layer
var flowDesign;
var formTwo;
var boolean=false;
var dataToAll;//全部数据
var theTrigger=[];//触发器
var jsondata = {
    "title": "",
    "nodes": {},
    "lines": {},
    "areas": {},
    "initNum": 0
}
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}
var flowstr=getQueryString('flowId');
var formIdstr=getQueryString('formId');
var alertData;//条件设置字段
var flowidurl=window.location.href;
var numId={};
var conditionsDate;//条件数据
var canwritefieldtwo;//可写字段
var forimId;
var numIds={};
var newLineload;//新建线开始数据
var newLineloadTwo;//新建线开始数据
var newLineend=[];//新建线结束数据
var prcsIdTwo;
var designdata=[];
var newlinebool=false;
var theTriggers;//逻辑接口数据
var theTriggerchufatwo;//逻辑接口数据
var trueFile;//是否允许上传附件
var newnodebool=false;
var oidPrcsId=null;//判断prcsid是否重复
var prevAndNextTitle=[
    '选择工具按钮，用于选中节点按钮。',
    '节点连线按钮，可以进行各个节点之间的连接。',
    '流程开始节点按钮，选中后可以新建圆形的开始节点。',
    '流程步骤节点按钮，选中后可以新建进行中的节点。',
    '流程结束节点按钮，选中后可以新建结束类型的节点。',
    '每个节点信息修改后，请点击保存按钮进行保存。',
    '每一节点就是一个步骤，每一个步骤存在各种各样的功能，配合表单设计器设计出的表单实现复杂的流程需求。',
    '记得每新建完一个步骤，都要设置相应的重要属性哦！比如您想让谁可以新建、办理一个步骤，记得在经办人中设置他的名字哦！',
    '如果存在正在流转中的流程，请谨慎调整这个流程，切忌不要随意删除中间的步骤，可能会导致流程出现办理错乱的问题哦！',
    '设置完节点信息后，记得要点击保存才能保存调整过的设置属性哦！',
]
var endReturn=0;
var allUser=""
var operationData = []


var num = $('input[name="timeAutoTurn"]:radio:checked').val();
$('[name="timeAutoTurn"]').val(num);



if(num==0){
    $("#yunxu").attr("checked","checked")
}





function selectOption(data) {//bottomstepstwoss部分select全部回显
    if(data==''){
        return
    }
    $('#bottomstepstwoss select option').each(function (i,n) {
        if($(this).val()==data){
            $(this).attr('selected')
        }
    })
}

$.get('/flow/selectAllFlow',{'flowId':flowstr},function (json) {//流程属性查询，是否允许上传附件
    if(json.flag){
        trueFile=json.object.flowDoc
    }

},'json')

$.get('/operation/selectAllFlowOperation', function(res) {
    if (res.flag) {
        operationData = res.object;
    }
});


function theTriggersTwo(fn) {//触发器业务逻辑接口查询
    $.get('/flowhook/getHookAll',function (json) {
        theTriggers=json.obj;
        if(fn!=undefined){
            fn();
        }
    },'json')
}
function theTriggerchufa(fn) {//触发器查询
    $.get('/tigger/showPlugin',function (json) {
        theTriggerchufatwo=json.obj;
        if(fn!=undefined){
            fn();
        }
    },'json')
}


function saveOrUpdate(fn) {//新建节点
    if(numId.prcsName.indexOf('.') > -1){
        numId.prcsName = numId.prcsName.split('.')[1];
    }else{

    }
    var data = JSON.parse(JSON.stringify(numId))
    data.relationWorkYn = '0'
    var layerMsg = layer.load(1,{ // 此处1没有意义，随便写个东西
        icon: 0, // 0~2 ,0比较好看
        shade: [0.01,'black'] // 黑色透明度0.5背景
    });
    $.post('/flowProcess/insert',data,function (json) {

        if (json.flag) {
            // prcsIdTwo=json.object.id
            //
            // var objDates={};
            // objDates.prcsName=numId.prcsName;
            // objDates.prcsId=numId.prcsId;
            // objDates.data=json.object;
            //
            // $('#node_'+objDates.prcsId).attr('data-num',prcsIdTwo)
            //
            // designdata.push(objDates)

            if(fn!=undefined){
                fn()
            }
            layer.close(layerMsg)
            // refresh()
            // ajaxSvg()

        }else{
            if(json.msg != undefined&&json.msg != ''){
                alert(json.msg);
            }else{
                alert("新建流程节点失败");
            }
            location.reload();
            layer.close(layerMsg)


        }
    },'json')
}

function savemobile() {//移动节点
    numIds.id=$("#ele_designerId").val();

    $.post('/flowProcess/updateTopAndLeft',numIds,function (json) {
        if (json.flag) {
            // console.log('成功')
        }else{
            alert("新建流程节点失败");
        }
    },'json')
}
function theNewLine(numdesignerId,numdesignerObj) {//新建连线
    var lineStrData;
    if(newLineend != ''){
        if(newLineend.length==1){
            lineStrData=newLineend.join(',')+',';
        }else {
            lineStrData = newLineend.join(',')+',';
        }
        $.post('/flowProcess/updateTopAndLeft',{'id':numdesignerId,'prcsTo':lineStrData},function (json) {
            if (json.flag) {

                numdesignerObj.data.prcsTo=(numdesignerObj.data.prcsTo+=lineStrData).split(',').removeDuplicate().join(',');

                $('[name="prcsTo"]').val(numdesignerObj.data.prcsTo);

                var prcsTosloo = $('[name="prcsTo"]').val().split(',');

                var prcsToStrtwo = '';
                for (var mx = 0; mx < prcsTosloo.length; mx++) {
                    for (var ix = 0; ix < designdata.length; ix++) {
                        if (prcsTosloo[mx] == designdata[ix].prcsId) {
                            prcsToStrtwo += '<li>' + designdata[ix].prcsName + ',</li>'
                        }
                    }
                }
                $('#candidatesPoneli').html(prcsToStrtwo)

            }else{
                alert("新建流程节点失败");
            }
        },'json')
    }

}

function inputTheEcho(names,dataNames,fn) {  //input回显
    $('[name="'+names+'"]').val(dataNames)
    if(typeof fn == 'function'){
        fn()
    }
}
function seleTheEcho(names,dataNames) {  //下拉框回显
    if(dataNames==undefined)return
    if(dataNames==''){
        dataNames = '0';
    }
    $('[name="'+names+'"]').next().find('dd').each(function (i,n) {
        if($(this).attr('lay-value')==dataNames){
            $(this).parent().prev().find('input').val($(this).text())
            $(this).parent().parent().prev().val(dataNames)
        }
    })
}


function radioTheEcho(names,dataNames) {
    $('[name="'+names+'"]').each(function (i,n) {

        if($(this).val()==dataNames){
            $(this).prop('checked',true);
            $(this).next().click();
        }
    })
}
function ulTheEcho(names,dataNames) {

    if(dataNames==undefined||dataNames=='')return
    var ularr=dataNames.split(',');
    if(ularr[ularr.length-1]==''){
        var ularrnums=ularr.length-1
        ularr.splice(ularrnums,1)
    }
    var ulStr='';
        for (var is = 0; is < ularr.length; is++) {
            if(ularr[is]=='[A@]'){
                ulStr += '<li>(' + (is + 1) + ')流程公共附件</li>'
            }else if(ularr[is]=='[B@]'){
                ulStr += '<li>(' + (is + 1) + ')工作名称/文号</li>'
            }else if(ularr[is]=='[C@]'){
                ulStr += '<li>(' + (is + 1) + ')紧急程度</li>'
            }else {
                ulStr += '<li>(' + (is + 1) + ')'+ularr[is]+'</li>'
            }
        }
        $('#' + names).html(ulStr)
}

function checkboxTheEcho(names,dataNames) {
    if(dataNames==undefined||dataNames=='')return;
    var arrcheck=dataNames.split(',');
    $('[name="'+names+'"]').each(function (i,n) {
        for (var g=0;g<arrcheck.length;g++){
            if($(this).val()==arrcheck[g]){
                $(this).prop('checked',true);
                $(this).next().addClass('layui-form-checked');
            }
        }
    })
}

function clearinput() {
    $('#propertyForm input').each(function (i,n) {
        $(this).val('')
    })
    $('input[type=radio]').each(function (i,n) {
        $(this).prop('checked',false);
    })
    $('input[type=checkbox]').each(function (i,n) {
        $(this).prop('checked',false);
    })
    $('textarea').each(function (i,n) {
        $(this).val()
    })
    $('#candidatesPoneli').html('')
    formTwo.render();
}
// function refresh(){
//     $.ajax({
//         type: 'get',
//         url: '/flowProcess/flowview',
//         dataType: 'json',
//         data: {"flowId": flowstr},
//         success: function (json) {
//             // debugger;
// //                    获取数据并添加到流程设计器的插件中
//             if (json.flag) {
//                 jsondata = {
//                     "title": "",
//                     "nodes": {},
//                     "lines": {},
//                     "areas": {},
//                     "initNum": 0
//                 }
//                 if (json.object == undefined) {
//                     designdata = [];
//                     var connections = [];
//                 } else {
//                     designdata = json.object.designdata;
//                     var connections = json.object.connections;
//                     jsondata.title = json.object.designdata[0].flowTypeModel.flowName;
//                     jsondata.initNum = designdata.length;
//                 }
//
//
//                 designdata.forEach(function (v, i) {
//
//                     jsondata.nodes['node_' + v.prcsId] = {
//                         designerId: v.id,
//                         name: v.prcsId + "." + v.prcsName,
//                         left: v.setLeft,
//                         type: v.setType,
//                         top: v.setTop,
//                         data: {
//                             allUser: v.allUser,
//                             prcsId: v.prcsId,
//                             prcsType: v.prcsType,
//                             prcsName: v.prcsName,
//                             //下一步骤
//                             prcsUser: v.prcsUser,
//                             prcsDept: v.prcsDept,
//                             prcsPriv: v.prcsPriv,
//                             signType: v.signType,
//                             countersign: v.countersign,
//                             userFilter: v.userFilter,
//                             autoType: v.autoType,
//                             topDefault: v.topDefault,//流转设置
//                             userLock: v.userLock,
//                             feedback: v.feedback,
//                             signlook: v.signlook,
//                             turnPriv: v.turnPriv,
//                             allowBack: v.allowBack,
//                             syncDeal: v.syncDeal,
//                             gatherNode: v.gatherNode,
//                             viewPriv: v.viewPriv,
//                             prcsTo: v.prcsTo,
//                             canWriteField: {
//                                 controlMode: v.controlMode,
//                                 fileuploadPriv: v.fileuploadPriv,
//                                 imguploadPriv: v.imguploadPriv,
//                                 attachPriv: v.attachPriv,
//                                 attachEditPriv: v.attachEditPriv,
//                                 attachEditPrivOnline: v.attachEditPrivOnline,
//                                 attachMacroMark: v.attachMacroMark,
//                                 prcsItem: v.prcsItem,
//                                 prcsItemAuto: v.prcsItemAuto,
//                                 documentEditPriv: v.documentEditPriv,
//                                 documentEditPrivDetail: v.documentEditPrivDetail,
//                                 fileuploadPriv: v.fileuploadPriv,
//                                 imguploadPriv: v.imguploadPriv
//                             },//可写字段
//                             hiddenItem: v.hiddenItem,
//                             requiredItem: v.requiredItem,
//                             conditionsSet: {
//                                 conditionDesc: v.conditionDesc,//不符合条件公式时，给用户的文字描述
//                                 typeJudgments: v.typeJudgments,
//                                 prcsInSet: v.prcsInSet,
//                                 conditionDesc: v.conditionDesc,
//                                 prcsOutSet: v.prcsOutSet,
//                                 prcsIn: v.prcsIn,
//                                 prcsOut: v.prcsOut
//                             },
//                             flowTiggerModel: v.flowTiggerModel,
//                             timeOut: v.timeOut,
//                             timeOutModify: v.timeOutModify,
//                             timeOutType: v.timeOutType,
//                             workingdaysType: v.workingdaysType,
//                             timeOutAttend: v.timeOutAttend,
//                             userFilter: v.userFilter,
//                             userFilterPrcsDept: v.userFilterPrcsDept,
//                             userFilterPrcsDeptName: v.userFilterPrcsDeptName,
//                             userFilterPrcsDeptOther: v.userFilterPrcsDeptOther,
//                             userFilterPrcsDeptOtherName: v.userFilterPrcsDeptOtherName,
//                             userFilterPrcsPriv: v.userFilterPrcsPriv,
//                             userFilterPrcsPrivName: v.userFilterPrcsPrivName,
//                             userFilterPrcsPrivOther: v.userFilterPrcsPrivOther,
//                             userFilterPrcsPrivOtherName: v.userFilterPrcsPrivOtherName,
//                             autoType: v.autoType,
//                             autoBaseUser: v.autoBaseUser,
//                             autoDept: v.autoDept,
//                             autoDeptName: v.autoDeptName,
//                             autoUserOp: v.autoUserOp,
//                             autoUserOpName: v.autoUserOpName,
//                             autoUser: v.autoUser,
//                             autoUserName: v.autoUserName,
//                             prcsPrivName: v.prcsPrivName,
//                             prcsUserName: v.prcsUserName,
//                             prcsDeptName: v.prcsDeptName,
//                             prcsDeptNo: v.prcsDeptNo,
//                             prcsUserPrivName: v.prcsUserPrivName,
//                             formIds: v.flowTypeModel.formId,
//                             childFlow: v.childFlow,
//                             relationIn: v.relationIn,
//                             relationOut: v.relationOut,
//                             autoUserReturn: v.autoUserReturn,
//                             autoUserOpReturn: v.autoUserOpReturn
//                             //触发器
//                             //提醒设置
//                             //呈批单设置
//                         }
//                     }
//                     conditionsDate = jsondata.nodes['node_' + v.prcsId].data.conditionsSet;
//                     canwritefieldtwo = jsondata.nodes['node_' + v.prcsId].data.canWriteField;
//                 });
//
//             }
//         }
//     })
// }

function  ajaxSvg() {
    $.ajax({
        type: 'get',
        url: '/flowProcess/flowview',
        dataType: 'json',
        data: {"flowId":flowstr},
        success: function (json) {
            // debugger;
            //获取数据并添加到流程设计器的插件中
            if (json.flag) {
                jsondata={
                    "title": "",
                    "nodes": {},
                    "lines": {},
                    "areas": {},
                    "initNum": 0
                }
                if(json.object==undefined){
                    designdata=[];
                    var connections=[];
                }else {
                    designdata = json.object.designdata;
                    var connections = json.object.connections;
                    jsondata.title = json.object.flowName;
                    jsondata.initNum = designdata.length;
                }



                 var relationId = '';
                $.ajax({
                    url:'/relationFunc/showRelation',
                    data:{formId:formIdstr},
                    dataType:'json',
                    type:'get',
                    async:false,
                    success:function(res){
                        var str = '<option value="0">请选择</option>';
                        if(res.flag){
                            var obj = res.obj;
                            for(var i=0;i<obj.length;i++){
                                str += '<option value="'+ obj[i].relationId +'">'+ obj[i].funcName +'</option>';
                            }

                        }
                        $('.AffApp').html('<select name="relationId" lay-verify="relationId">'+ str +'</select>');
                        form.render();
                        relationId = 0;
                    }
                });
                designdata.forEach(function (v, i) {
                    if(v.setLeft == 0&&v.setTop == 0){
                        var left = v.setLeft;
                        var top = v.setTop;
                        v.setLeft = Math.ceil((i+1)/2)*200 - 100;
                        if((i+1)%2 == 0){
                            v.setTop = 400;
                        }else{
                            v.setTop = 200;
                        }
                    }
                    if(v.relationId != undefined){
                        relationId = v.relationId;
                    }
                    jsondata.nodes['node_' + v.prcsId] = {
                        designerId:v.id,
                        name: v.prcsId +"."+ v.prcsName,
                        left: v.setLeft,
                        type: v.setType,
                        top: v.setTop,
                        data:{
                            relationId:relationId,
                            allUser:v.allUser,
                            prcsId:v.prcsId,
                            prcsType:v.prcsType,
                            prcsName:v.prcsName,
                            //下一步骤
                            prcsUser:v.prcsUser,
                            prcsDept:v.prcsDept,
                            prcsPriv:v.prcsPriv,
                            signType:v.signType,
                            countersign:v.countersign,
                            countersignAgain:v.countersignAgain,
                            relationWorkYn:v.relationWorkYn,
                            userFilter:v.userFilter,
                            autoType:v.autoType,
                            topDefault:v.topDefault,//流转设置
                            userLock:v.userLock,
                            feedback:v.feedback,
                            signlook:v.signlook,
                            turnPriv:v.turnPriv,
                            allowBack:v.allowBack,
                            syncDeal:v.syncDeal,
                            gatherNode:v.gatherNode,
                            viewPriv:v.viewPriv,
                            turnContinueYn:v.turnContinueYn,
                            presetYN:v.presetYN,
                            prcsTo:v.prcsTo,
                            operationButton: v.operationButton,
                            canWriteField:{
                                controlMode:v.controlMode,
                                fileuploadPriv:v.fileuploadPriv,
                                imguploadPriv:v.imguploadPriv,
                                attachPriv:v.attachPriv,
                                attachEditPriv:v.attachEditPriv,
                                attachEditPrivOnline:v.attachEditPrivOnline,
                                attachMacroMark:v.attachMacroMark,
                                noMainSignerFileYn: v.noMainSignerFileYn,
                                prcsItem:v.prcsItem,
                                prcsItemAuto:v.prcsItemAuto,
                                documentEditPriv:v.documentEditPriv,
                                documentEditPrivDetail:v.documentEditPrivDetail,
                                fileuploadPriv:v.fileuploadPriv,
                                imguploadPriv:v.imguploadPriv
                            },//可写字段
                            hiddenItem:v.hiddenItem,
                            requiredItem:v.requiredItem,
                            conditionsSet:{
                                conditionDesc:v.conditionDesc,//不符合条件公式时，给用户的文字描述
                                typeJudgments:v.typeJudgments,
                                prcsInSet:v.prcsInSet,
                                conditionDesc:v.conditionDesc,
                                prcsOutSet:v.prcsOutSet,
                                prcsIn:v.prcsIn,
                                prcsOut:v.prcsOut
                            },
                            flowTiggerModel:v.flowTiggerModel,
                            timeAutoTurn:v.timeAutoTurn,
                            timeOut:v.timeOut,
                            timeOutModify:v.timeOutModify,
                            timeOutType:v.timeOutType,
                            workingdaysType:v.workingdaysType,
                            timeOutAttend:v.timeOutAttend,
                            userFilter:v.userFilter,
                            userFilterPrcsDept:v.userFilterPrcsDept,
                            userFilterPrcsDeptName:v.userFilterPrcsDeptName,
                            userFilterPrcsDeptOther:v.userFilterPrcsDeptOther,
                            userFilterPrcsDeptOtherName:v.userFilterPrcsDeptOtherName,
                            userFilterPrcsPriv:v.userFilterPrcsPriv,
                            userFilterPrcsPrivName:v.userFilterPrcsPrivName,
                            userFilterPrcsPrivOther:v.userFilterPrcsPrivOther,
                            userFilterPrcsPrivOtherName:v.userFilterPrcsPrivOtherName,
                            autoType:v.autoType,
                            autoBaseUser:v.autoBaseUser,
                            autoDept:v.autoDept,
                            autoDeptName:v.autoDeptName,
                            autoUserOp:v.autoUserOp,
                            autoUserOpName:v.autoUserOpName,
                            autoUser:v.autoUser,
                            autoUserName:v.autoUserName,
                            prcsPrivName:v. prcsPrivName,
                            prcsUserName:v.prcsUserName,
                            prcsDeptName:v.prcsDeptName,
                            prcsDeptNo:v.prcsDeptNo,
                            prcsUserPrivName:v.prcsUserPrivName,
                            formIds:v.flowTypeModel.formId,
                            childFlow:v.childFlow,
                            relationIn:v.relationIn,
                            relationOut:v.relationOut,
                            autoUserReturn:v.autoUserReturn,
                            autoUserOpReturn:v.autoUserOpReturn,
                            plugin:v.plugin,
                            pluginSave:v.pluginSave,
                            file:v. file,
                            rmsRollRoom:v.rmsRollRoom,
                            rmsRoll:v.rmsRoll,
                            fileRule:v.fileRule,
                            mappingRule:v.mappingRule,
                            fileContent:v.fileContent,


                            //触发器
                            //提醒设置
                            //呈批单设置
                        }
                    }
                });
                connections.forEach(function (v, i) {
                    jsondata.lines['line_' + i] = {
                        type: "sl",
                        from: "node_" + v.from,
                        to: "node_" + v.to,
                        name: designdata[v.from],
                        "M": 41.5,
                        alt: true
                    }
                });
            }
            flowDesign.onItemDel = function (id, type) {
                if (confirm("确定要删除步骤吗?")) {
                    return true;
                } else {
                    return false;
                }
            };
            flowDesign.onItemDel1 = function (id, type) {
                if (confirm("确定要删除连线吗?")) {
                    return true;
                } else {
                    return false;
                }
            };


            flowDesign.loadData(jsondata);
            flowDesign.onItemRename=function (id,name,type) {
                layer.alert('请通过侧边栏修改节点名字')
                return false;
            }
            flowDesign.onItemFocus = function (id, model) {
                    var obj;
                    $("#ele_model").val(model);
                    $("#ele_id").val(id);

                    if (model == "line") {
                        obj = this.$lineData[id];

                        $("#ele_type").val(obj.M);
                        $("#ele_left").val("");
                        $("#ele_top").val("");
                        $("#ele_width").val("");
                        $("#ele_height").val("");
                        $("#ele_designerId").val("");
                        $("#ele_from").val(obj.from);
                        $("#ele_to").val(obj.to);
                        $("#ele_flow").val("");


                    } else if (model == "node") {
                        if (parseInt($('#propertyForm').css('right')) < 0) {
                            if($('#propertyForm .active').length == 1){

                            }else{
                                $('#propertyForm .setUpThe').eq(0).click();
                            }
                            $('#propertyForm').css('right', '0px')
                            $('.btnstorage').css('right', '0px')
                        } else {
                            $('#propertyForm').css('right', -$('#propertyForm').width()+12)
                            $('.btnstorage').css('right', -$('.btnstorage').width())
                            setTimeout(function () {
                                $('#propertyForm').css('right', '0px')
                                $('.btnstorage').css('right', '0px')
                            }, 250)
                        }
                        obj = this.$nodeData[id];

                        var nodeArr=this.$nodeDom;
                        for(var DomNodei in nodeArr){
                            $(nodeArr[DomNodei]).removeClass('active')
                        }
                        $(this.$nodeDom[id]).addClass('active')
                        $("#ele_type").val(obj.type);
                        $("#ele_designerId").val(obj.designerId);
                        $("#ele_left").val(obj.left);
                        $("#ele_top").val(obj.top);
                        $("#ele_width").val(obj.width);
                        $("#ele_height").val(obj.height);
                        $("#ele_flow").val('${formId}');
                        var objtwo = obj.data;

                        if(objtwo != undefined){
                            allUser = objtwo.allUser
                        }else{
                            if(obj.name.indexOf('.')>-1){
                                var index = obj.name.split('.')[0]
                                objtwo = designdata[(Number(index)-1)]
                                obj.data = objtwo.data
                                
                            }

                        }
                        $('#requiredItem').html('')
                        $.ajax({
                            url:'/flowProcess/getSonFlow',
                            data:{flowId:flowstr,prcsId:objtwo.prcsId},
                            dataType:'json',
                            type:'get',
                            success:function(res){
                                var data = res.obj;
                                var str="";
                                for(var i=0;i<data.length;i++){
                                    str += '<option value="'+data[i].prcsId+'">'+data[i].prcsId+'.'+data[i].prcsName+'</option>'
                                }
                                if(data.length != 0){
                                    $('.returnStep').html(str);
                                }
                                if($('.return').css('display')!='none'){
                                    //针对后台返回值带有逗号，需对prcsTo进行特殊处理
                                    if(objtwo.prcsTo.indexOf(',')!=-1){
                                        $('.returnStep option[value="'+objtwo.prcsTo.substring(0,objtwo.prcsTo.length-1)+'"]').prop('selected','selected')
                                    }else {
                                        $('.returnStep option[value="'+objtwo.prcsTo+'"]').prop('selected','selected')
                                    }

                                }
                                if(data.length != 0){
                                    formTwo.render()
                                }

                                nums=data.timeAutoTurn

                            }
                        })

                        dataToAll = designdata;//所有数据
                        var stringdata = '<option value="0">当前步骤</option>';
                        for (var il = 0; il < dataToAll.length; il++) {
                            stringdata += '<option value="' + dataToAll[il].prcsId + '">' + dataToAll[il].prcsName + '</option>'
                        }
                        $('[name="autoBaseUser"]').html(stringdata)
                        $('[name="AUTO_PRCS_USER"]').html(stringdata)
                        formTwo.render();

                        if(obj.data==undefined){
                            clearinput();
                            $("#ele_designerId").val($('#node_'+id.replace('node_','')).attr('data-num'));
                            $('[name="prcsId"]').val(id.replace('node_',''))
                            $('[name="prcsName"]').val(id.replace('node_','步骤'))
                            $('#query_userId').val('')
                            $('#department').val('')
                            $('#theScopeOf').val('')
                            $('[name="prcsUser"]').val('')
                            $('[name="prcsDept"]').val('')
                            $('[name="prcsPriv"]').val('')
                            oidPrcsId=id.replace('node_','');

                            return true;
                        }

                        seleTheEcho('userFilter', objtwo.userFilter)
                        if ($('[name="userFilter"]').val() == 6) {
                            $('.departmentAgent').show();
                            $('.auxiliaryDepartmentAgent').hide();
                            $('.theSpecifiedRole').hide();
                            $('.assignRole').hide();

                        } else if ($('[name="userFilter"]').val() == 9) {
                            $('.auxiliaryDepartmentAgent').show()
                            $('.departmentAgent').hide();
                            $('.theSpecifiedRole').hide();
                            $('.assignRole').hide();
                        } else if ($('[name="userFilter"]').val() == 7) {
                            $('.theSpecifiedRole').show()
                            $('.departmentAgent').hide();
                            $('.auxiliaryDepartmentAgent').hide();
                            $('.assignRole').hide();
                        } else if ($('[name="userFilter"]').val() == 11) {
                            $('.assignRole').show()
                            $('.departmentAgent').hide();
                            $('.auxiliaryDepartmentAgent').hide();
                            $('.theSpecifiedRole').hide();
                        }else{
                            $('.assignRole').hide()
                            $('.departmentAgent').hide();
                            $('.auxiliaryDepartmentAgent').hide();
                            $('.theSpecifiedRole').hide();
                        }
                        seleTheEcho('autoType', objtwo.autoType)
                        if ($('[name="autoType"]').val() == 2 || $('[name="autoType"]').val() == 9 || $('[name="autoType"]').val() == 4
                            || $('[name="autoType"]').val() == 6 || $('[name="autoType"]').val() == 5 ||
                            $('[name="autoType"]').val() == 10 || $('[name="autoType"]').val() == 11) {
                            $('.autoBaseUser').show();
                            $('.optionalDepartmentAgent').hide()
                            $('.specifyTheHost').hide()
                            $('.oneTheHost').hide()
                            $('.stepsTwos').hide()
                        } else if ($('[name="autoType"]').val() == 12 || $('[name="autoType"]').val() == 13 ||
                            $('[name="autoType"]').val() == 14 || $('[name="autoType"]').val() == 15) {
                            $('.optionalDepartmentAgent').show()
                            $('.autoBaseUser').hide();
                            $('.specifyTheHost').hide()
                            $('.oneTheHost').hide()
                            $('.stepsTwos').hide()
                        } else if ($('[name="autoType"]').val() == 3) {
                            $('.specifyTheHost').show()
                            $('.autoBaseUser').hide();
                            $('.optionalDepartmentAgent').hide()
                            $('.oneTheHost').hide()
                            $('.stepsTwos').hide()
                        } else if ($('[name="autoType"]').val() == 7) {
                            $('.oneTheHost').show()
                            $('.autoBaseUser').hide();
                            $('.optionalDepartmentAgent').hide()
                            $('.specifyTheHost').hide()
                            $('.stepsTwos').hide()
                        } else if ($('[name="autoType"]').val() == 8) {
                            $('.autoBaseUser').show();
                            $('.stepsTwos').hide()
                            $('.optionalDepartmentAgent').hide()
                            $('.specifyTheHost').hide()
                            $('.oneTheHost').hide()
                        }else{
                            $('.autoBaseUser').hide();
                            $('.stepsTwos').hide()
                            $('.optionalDepartmentAgent').hide()
                            $('.specifyTheHost').hide()
                            $('.oneTheHost').hide()
                        }


                            file=objtwo.file
                            rmsRollRoom=objtwo.rmsRollRoom
                        rmsRoll=objtwo.rmsRoll
                        fileRule=objtwo.fileRule
                        mappingRule=objtwo.mappingRule
                        fileContent=objtwo.fileContent

                        inputTheEcho('prcsId', objtwo.prcsId)
                        inputTheEcho('childFlow', objtwo.childFlow)
                        inputTheEcho('relationIn', objtwo.relationIn)
                        inputTheEcho('relationOut', objtwo.relationOut)
                        inputTheEcho('plugin', objtwo.plugin)
                        inputTheEcho('pluginSave', objtwo.pluginSave)
                        oidPrcsId=objtwo.prcsId;

                        inputTheEcho('prcsDeptName', objtwo.prcsDeptName,function () {
                            $('[name="prcsDeptName"]').attr('deptname',objtwo.prcsDept)
                        })
                        inputTheEcho('prcsUserName', objtwo.prcsUserName,function () {
                            $('[name="prcsUserName"]').attr('username',objtwo.prcsUserName)
                            $('[name="prcsUserName"]').attr('userprivname',objtwo.prcsUserPrivName)
                        })
                        inputTheEcho('prcsPrivName', objtwo.prcsPrivName,function () {
                            // $('[name="prcsPrivName"]').attr('username',objtwo.prcsUserName)
                        })
                        inputTheEcho('autoUserOpReturn', objtwo.autoUserOpReturn)
                        inputTheEcho('autoUserReturn', objtwo.autoUserReturn)
                        $('#autoUserOpReturn').val(objtwo.autoUserOpName)
                        $('#autoUserReturn').val(objtwo.autoUserName)


                        seleTheEcho('prcsType', objtwo.prcsType)
                        seleTheEcho('relationId', objtwo.relationId)
                        if(objtwo.prcsType == 1){
                            $('.setUpThe').hide();
                            $('.setUpThe').eq(0).show();
                            $('.setUpThe').eq(2).show();
                            $('.setUpThe').eq(7).show();
                            $('.setUpThe').eq(10).show();
                            $('.flowChild').show()
                            $('.step').hide()
                        }else{
                            $('.setUpThe').show();
                            $('.flowChild').hide()
                            $('.step').show()
                        }
                        if(objtwo.prcsType == 1 && objtwo.prcsTo!=""){
                            $('.endReturn').eq(1).prop('checked',true)
                            $('.endReturn').eq(0).prop('checked',false)
                            $('.flowChilds').show();
                            endReturn = 1
                        }else{
                            $('.endReturn').eq(1).prop('checked',false)
                            $('.endReturn').eq(0).prop('checked',true)
                            $('.flowChilds').hide();
                            endReturn = 0
                        }
                        inputTheEcho('prcsName', objtwo.prcsName)
                        inputTheEcho('prcsTo', objtwo.prcsTo)

                        inputTheEcho('prcsUser', objtwo.prcsUser,function(){
                            $('[name="prcsUserName"]').attr('user_id',objtwo.prcsUser)
                            $('[name="prcsUserName"]').attr('dataid','')
                        })
                        inputTheEcho('prcsDept', objtwo.prcsDept,function () {
                            $('[name="prcsDeptName"]').attr('deptid',objtwo.prcsDept)
                            $('[name="prcsDeptName"]').attr('deptno',objtwo.prcsDeptNo)
                            $('[name="prcsDeptName"]').attr('deptname',objtwo.prcsDeptName)
                        })
                        inputTheEcho('prcsPriv', objtwo.prcsPriv,function () {
                            $('[name="prcsPrivName"]').attr('userpriv',objtwo.prcsPriv)
                        })
                        inputTheEcho('hiddenItem', objtwo.hiddenItem)
                        inputTheEcho('requiredItem', objtwo.requiredItem)
                        inputTheEcho('operationButton', objtwo.operationButton)
                        ulTheEcho('hiddenItem', objtwo.hiddenItem)
                        ulTheEcho('requiredItem', objtwo.requiredItem)
                        radioTheEcho('signType', objtwo.signType)
                        radioTheEcho('countersign', objtwo.countersign)
                        radioTheEcho('countersignAgain', objtwo.countersignAgain)
                        radioTheEcho('relationWorkYn', objtwo.relationWorkYn)
                        if(objtwo.timeOut!=undefined){
                            $('[name="timeOut"]').val(objtwo.timeOut.split(',')[0])
                            $('.btnTime').attr('data-type',objtwo.timeOut.split(',')[1])
                            if(objtwo.timeOut.split(',')[1]=='hour'){
                                $('.btnTime').text('小时')
                            }else if(objtwo.timeOut.split(',')[1]=='day'){
                                $('.btnTime').text('天')
                            }
                        }
                        radioTheEcho('timeAutoTurn', objtwo.timeAutoTurn)
                        radioTheEcho('timeOutModify', objtwo.timeOutModify)
                        radioTheEcho('timeOutType', objtwo.timeOutType)
                        radioTheEcho('workingdaysType', objtwo.workingdaysType)
                        radioTheEcho('timeOutAttend', objtwo.timeOutAttend)
                        radioTheEcho('topDefault', objtwo.topDefault)
                        radioTheEcho('userLock', objtwo.userLock)
                        radioTheEcho('feedback', objtwo.feedback)
                        radioTheEcho('signlook', objtwo.signlook)
                        radioTheEcho('turnPriv', objtwo.turnPriv)
                        radioTheEcho('allowBack', objtwo.allowBack)
                        radioTheEcho('syncDeal', objtwo.syncDeal)
                        radioTheEcho('gatherNode', objtwo.gatherNode)
                        radioTheEcho('viewPriv', objtwo.viewPriv)
                        radioTheEcho('turnContinueYn',objtwo.turnContinueYn)
                        radioTheEcho('presetYN',objtwo.presetYN)
                        seleTheEcho('autoBaseUser', objtwo.autoBaseUser)
                        inputTheEcho('autoUserOp', objtwo.autoUserOp)
                        $('#xuanzezhuban').attr('zbperson','');
                        if(objtwo.autoType == 3){
                            $('#xuanzezhuban').val(objtwo.autoUserOpName).attr('dataid','').attr('user_id',objtwo.autoUserOp);
                            $('#specifyTheHost').val(objtwo.autoUserName).attr('dataid','').attr('user_id',objtwo.autoUser);
                        }
                        if(objtwo.autoType == 12||objtwo.autoType == 13||objtwo.autoType == 14||objtwo.autoType == 15){
                            $('#optionalDepartmentAgent').val(objtwo.autoDeptName).attr('deptid',objtwo.autoDept)
                        }

                        inputTheEcho('autoUser', objtwo.autoUser)
                        inputTheEcho('autoDept', objtwo.autoDept)
                        inputTheEcho('userFilterPrcsDept', objtwo.userFilterPrcsDept)
                        if(objtwo.userFilterPrcsDeptName == undefined){
                            objtwo.userFilterPrcsDeptName = '';
                        }else{
                            if(objtwo.userFilterPrcsDeptName.substr(objtwo.userFilterPrcsDeptName.length-1) != ',')
                            objtwo.userFilterPrcsDeptName += ',';
                        }
                        $('#departmentAgent').val(objtwo.userFilterPrcsDeptName).attr('deptid',objtwo.userFilterPrcsDept)
                        inputTheEcho('userFilterPrcsDeptOther', objtwo.userFilterPrcsDeptOther)
                        $('#auxiliaryDepartmentAgent').attr('deptid',objtwo.userFilterPrcsDeptOther).val(objtwo.userFilterPrcsDeptOtherName);
                        inputTheEcho('userFilterPrcsPriv', objtwo.userFilterPrcsPriv)
                        $('#theSpecifiedRole').attr('userpriv',objtwo.userFilterPrcsPriv).val(objtwo.userFilterPrcsPrivName);
                        inputTheEcho('userFilterPrcsPrivOther', objtwo.userFilterPrcsPrivOther);
                        $('#assignRole').attr('userpriv',objtwo.userFilterPrcsPrivOther).val(objtwo.userFilterPrcsPrivOtherName);
                        theTrigger = objtwo.flowTiggerModel;
                        forimId = objtwo.formIds;
                        conditionsDate = objtwo.conditionsSet;
                        canwritefieldtwo = objtwo.canWriteField;


                        var canwritefieldobj={};
                        canwritefieldobj.prcsItem=canwritefieldtwo.prcsItem;
                        canwritefieldobj.prcsItemAuto = canwritefieldtwo.prcsItemAuto;
                        canwritefieldobj.attachPriv=canwritefieldtwo.attachPriv;
                        canwritefieldobj.attachEditPriv=canwritefieldtwo.attachEditPriv;
                        canwritefieldobj.attachEditPrivOnline=canwritefieldtwo.attachEditPrivOnline;
                        canwritefieldobj.attachMacroMark=canwritefieldtwo.attachMacroMark;
                        canwritefieldobj.noMainSignerFileYn=canwritefieldtwo.noMainSignerFileYn;
                        canwritefieldobj.documentEditPriv=canwritefieldtwo.documentEditPriv;
                        canwritefieldobj.documentEditPrivDetail=canwritefieldtwo.documentEditPrivDetail
                        $('[name="prcsItemTwo"]').val(JSON.stringify(canwritefieldobj))
                        $('[name="imguploadPriv"]').val(objtwo.canWriteField.imguploadPriv)
                        $('[name="fileuploadPriv"]').val(objtwo.canWriteField.fileuploadPriv)



                        var conditionsDateObj={};
                        conditionsDateObj.intoTheCondition={};
                        conditionsDateObj.intoTheCondition.list=conditionsDate.prcsIn;
                        conditionsDateObj.intoTheCondition.prcsInSet=conditionsDate.prcsInSet;
                        conditionsDateObj.intoTheCondition.conditionDesc=(function () {
                            if(conditionsDate.conditionDesc==undefined||conditionsDate.conditionDesc=='') {
                                return ''
                            }else {
                                if (conditionsDate.conditionDesc.split('\n')[0] == undefined
                                    || conditionsDate.conditionDesc.split('\n')[0] == '') {
                                    return ''
                                } else {
                                    return conditionsDate.conditionDesc.split('\n')[0]
                                }
                            }
                        })()
                        conditionsDateObj.transferConditions={}
                        conditionsDateObj.transferConditions.list=conditionsDate.prcsOut;
                        conditionsDateObj.transferConditions.prcsOutSet=conditionsDate.prcsOutSet;
                        conditionsDateObj.transferConditions.conditionDesc=(function () {
                            if(conditionsDate.conditionDesc==undefined||conditionsDate.conditionDesc=='') {
                                return ''
                            }else {
                                if(conditionsDate.conditionDesc.split('\n')[1]==undefined
                                    ||conditionsDate.conditionDesc.split('\n')[1]==''){
                                    return ''
                                }else {
                                    return conditionsDate.conditionDesc.split('\n')[1]
                                }
                            }
                        })()
                        conditionsDateObj.transferConditionTwo=conditionsDate.conditionDesc;
                        $('[name="settlementOfCondition"]').val(JSON.stringify(conditionsDateObj))



                        workForm.init({
                                formhtmlurl: '../../form/formType',
                                resdata: {
                                    fromId: forimId
                                },
                                flag: 3
                            },
                            function (data) {
                                alertData = data;
                                if(objtwo.autoType == 7){
                                    var obj = {};
                                    var str = '';
                                    var ITEM_IDTitle = '';
                                    $('.oneTheHost input[name=ITEM_ID]').val(objtwo.autoUser);
                                    for(var i=0;i<alertData.length;i++){
                                        obj[alertData[i].name] = {
                                            title:alertData[i].title
                                        }
                                        if(objtwo.autoUser != ''){
                                            for(var j=0;j<objtwo.autoUser.split(',').length;j++){
                                                if(alertData[i].name == objtwo.autoUser.split(',')[j]){
                                                    ITEM_IDTitle += '<li>' +alertData[i].title + '</li>';
                                                }
                                            }
                                        }
                                    }
                                    $('.oneTheHost input[name=ITEM_ID]').parent().siblings('ul').html(ITEM_IDTitle);

                                    objtwo.autoUser.split(',').forEach(function(v,i){
                                        if(v != ''){
                                            if(v.indexOf('DATA_')>-1){
                                                var title = obj[v].title;
                                            }else{
                                                var title = obj['DATA_'+v].title;
                                            }
                                            str += '<li>('+(i+1)+')'+title+'</li>'
                                        }
                                    })
                                    $('.oneTheHost ul').html(str);
                                }
                            });

                        //下一步骤
                        var prcsToStr = '';
                        if ($('[name="prcsTo"]').val() != '') {
                            var prcsTos = $('[name="prcsTo"]').val().split(',');
                            for (var mx = 0; mx < prcsTos.length; mx++) {
                                for (var ix = 0; ix < designdata.length; ix++) {
                                    if (prcsTos[mx] == designdata[ix].prcsId) {
                                        prcsToStr += '<li>' + designdata[ix].prcsName + ',</li>'
                                    }
                                }
                                if(mx!=prcsTos.length-1) {
                                    if (prcsTos[mx] == 0) {
                                        prcsToStr += '<li>结束,</li>'
                                    }
                                }
                            }
                        }
                        $('#candidatesPoneli').html(prcsToStr)

                        //关联操作设置
                        var operationButtonStr = '';
                        if ($('[name="operationButton"]').val() != '') {
                            var operationButtons = $('[name="operationButton"]').val().split(',');
                            for (var mx = 0; mx < operationButtons.length; mx++) {
                                for (var ix = 0; ix < operationData.length; ix++) {
                                    if (operationButtons[mx] == operationData[ix].opId) {
                                        operationButtonStr += '<li>' + operationData[ix].opName + ',</li>'
                                    }
                                }
                                if(mx!=operationButtons.length-1) {
                                    if (operationButtons[mx] == 0) {
                                        operationButtons += '<li>结束,</li>'
                                    }
                                }
                            }
                        }
                        $('#operationItem').html(operationButtonStr)

                    // }
                    }
                $("#ele_name").val(obj.name);


                    return true;

                }


        }
    });
}
//获取一个min-max范围的随机整数
function getRandom(min, max){
    var r = Math.random() * (max - min);
    var re = Math.round(r + min);
    re = Math.max(Math.min(re, max), min)

    return re;
}
$(function () {
    // var fromIdtwo = 17;

    var randomNum = getRandom(0, prevAndNextTitle.length);
    $('.fixedtitle .textP').text(prevAndNextTitle[randomNum]).attr('data-num',randomNum);
    
    $('.prevAndNext .prev').click(function () {
        var num=$(this).parent().prev().attr('data-num');
        if(num==0){
            $('.fixedtitle .textP').text(prevAndNextTitle[prevAndNextTitle.length-1])
            $('.fixedtitle .textP').attr('data-num',prevAndNextTitle.length-1)
        }else {
            $('.fixedtitle .textP').text(prevAndNextTitle[num-1])
            $('.fixedtitle .textP').attr('data-num',num-1)
        }
    })
    $('.prevAndNext .next').click(function () {
        var num=$(this).parent().prev().attr('data-num');
        if(num==(prevAndNextTitle.length-1)){
            $('.fixedtitle .textP').text(prevAndNextTitle[0])
            $('.fixedtitle .textP').attr('data-num',0)
        }else {
            $('.fixedtitle .textP').text(prevAndNextTitle[parseInt(num)+1])
            $('.fixedtitle .textP').attr('data-num',parseInt(num)+1)
        }
    })






    $('.emptyTwo').click(function () {
        var $this = $(this).parent().parent().find('textarea');
        if($this.attr('user_id')){
            $this.attr('user_id','');
        }else if($this.attr('deptid')){
            $this.attr('deptid','');
        }else if($this.attr('privid')){
            $this.attr('privid','');
        }else if($this.attr('userpriv')){
            $this.attr('userpriv','');
        }
        $(this).parent().parent().find('textarea').val('');
        $(this).parent().parent().find('input[type="hidden"]').val('');
    })




    $('.savetwo').click(function () {
        $('#flowId').val($.GetRequest().flowId)
        var prcsIdOnlyOne=$('[name="prcsId"]').val();
        if(oidPrcsId!=null) {
            if (oidPrcsId != prcsIdOnlyOne) {
                var prcsIdNum = true;
                for (var i = 0; i < designdata.length; i++) {
                    if (designdata[i].prcsId == prcsIdOnlyOne) {
                        prcsIdNum = false;
                    }
                }
                if (!prcsIdNum) {
                    $.layerMsg({content: '序号不能重复！', icon: 2});
                    return;
                }
            }
        }
        if($('select[name=prcsType]').val() == 1){
            if($('input[lay-filter=endReturn]:checked').val() == 0 ){
                $('input[name=prcsTo]').val('');
            }
        }
        $('[name="autoUserReturn"]').val($('#autoUserReturn').attr('user_id'))
        $('[name="autoUserOpReturn"]').val($('#autoUserOpReturn').attr('user_id'))
        if($('.return').css('display')!='none'){
            if($('.returnStep').val()=="back"){
                $.layerMsg({content: '返回步骤不能为空！', icon: 2});
                return;
            }
           /* if($('#autoUserOpReturn').val()==""&&$('#autoUserReturn').val()==""){
                $.layerMsg({content: '请选择主办人/经办人！', icon: 2});
                return;
            }*/
            $('[name="prcsTo"]').val($('.returnStep').val())
        }

        if($('[name="timeOut"]').val()!=''){
            var timeOutVal=$('[name="timeOut"]').val()+','+$('.btnTime').attr('data-type');
            $('[name="timeOut"]').val(timeOutVal);
        }

        $('.theControlData').each(function () {
            if($(this).attr('user_id')!=undefined) {
                $(this).next().val($(this).attr('user_id'))
                return true;
            }
             if($(this).attr('userpriv')!=undefined){
                $(this).next().val($(this).attr('userpriv'))
                return true
            }
            if($(this).attr('deptid')!=undefined){
                if($(this).hasClass('deptname')){
                    $(this).next().val($(this).attr('deptid').split(',')[0]);
                }else{
                    $(this).next().val($(this).attr('deptid'));
                }
                return true;
            }
            if($(this).attr('dataid')!=undefined) {
                $(this).next().val($(this).attr('dataid'))
                return true;
            }
        })

        if($(this).attr('data-type')) {
            $(this).attr('data-type',false);
            $('#zbinput').val($('#xuanzezhuban').attr('user_id'));
            if($('[name=autoType]').val() == 7){
                $('input[name=ITEM_ID]').val($('input[name=ITEM_ID]').val().split(',')[0]+',');
            }
            if($('[name=autoType]').val() == 3){
                if($('input[name=autoUser]').val()==''){
                    alert('智能选人选择指定选择默认人员功能,必须选择主办人!');
                }else{
                    if($('#xuanzezhuban').attr('user_id') == ''){
                        alert('智能选人选择指定选择默认人员功能，必须选择主办人！');
                        return false;
                    }else{
                        $('#datasave').ajaxSubmit({
                            type: 'post',
                            dataType: 'json',
                            success: function (json) {
                                if (json.flag) {
                                    $.layerMsg({content: '保存成功！', icon: 1}, function () {
                                        location.reload();
                                    });
                                } else {
                                    $(this).attr('data-type',true)
                                    alert('异常')
                                }

                            }
                        })
                    }
                }
            }else{
                $('#datasave').ajaxSubmit({
                    type: 'post',
                    dataType: 'json',
                    success: function (json) {
                        if (json.flag) {
                            $.layerMsg({content: '保存成功！', icon: 1}, function () {
                                location.reload();
                            });
                        } else {
                            $(this).attr('data-type',true)
                            alert('异常')
                        }

                    }
                })
            }

        }
    })

    $(document).delegate('#checkAll span .layui-form-checkbox','click',function () {
        if($(this).prev().is(':checked')){
            var bottomstepstwoVlue = '';
            $('.bottomstepstwo input[type=checkbox]').each(function (i,n) {
                $(this).prop('checked',true)
                $(this).next().addClass('layui-form-checked')
                if(!$(n).hasClass('checkedAll')){
                    bottomstepstwoVlue += $(n).val() + ',';
                }
            })
            $('.bottomstepstwo.layui-form').attr('value',bottomstepstwoVlue);
        }
        else {
            $('.bottomstepstwo input[type=checkbox]').each(function (i,n) {
                $(this).removeProp('checked')
                $(this).next().removeClass('layui-form-checked')

            })
            $('.bottomstepstwo.layui-form').attr('value','');
        }
    })
    $(document).delegate('.theEditor','click',function () {
        $(this).parent().parent().find('span').hide();
        $(this).parent().parent().find('input').show().focus();
        $(this).parent().parent().find('input').val($(this).parent().parent().find('input[type=hidden]').val());
    })

    $(document).delegate('#bottomstepstwoss table tbody input[type=text]','blur',function () {
       $(this).next().val($(this).val());
       $(this).hide();
       $(this).prev().text($(this).val())
        $(this).prev().show();
    })
    $(document).delegate('.deletes','click',function () {
        var $parents = $(this).parents('tbody');
        $(this).parents('tr').remove();
        for(var i=0;i<$parents.find('tr').length;i++){
            var j = i+1;
            $parents.find('tr').eq(i).find('td').eq(0).html(j);
        }
    })
    //
    $(document).delegate('#draw_flowDesignTable','click',function () {
       $('#propertyForm').css('right',-($('#propertyForm').width()+12))
       $('.btnstorage').css('right',-($('.btnstorage').width()))
    })




        var $width=$('body').width();
        var $height=parseInt(document.documentElement.clientHeight||document.body.offsetHeight);

        var property = {
            width: $width+2,
            height: $height-20,
            toolBtns: ["chat", "end round"],
//                "start round", "end round", "task round", "node","state", "plug", "join", "fork", "complex mix"
        haveHead: true,
        headBtns: [],//如果haveHead=true，则定义HEAD区的按钮
        haveTool: true,
        haveGroup: true,
        useOperStack: true
    };
    var remark = {
        cursor: "选择节点",
        direct: "结点连线",
        start: "开始节点",
        end: "结束结点",
        task: "任务结点",
        node: "自动结点",
        chat: "进行中结点",
        state: "状态结点",
        plug: "附加插件",
        fork: "分支结点",
        join: "联合结点",
        "complex mix": "复合结点",
        "end round": "结束节点",
        group: "组织划分框编辑开关"
    };
    flowDesign = $.createGooFlow($("#flowDesignTable"), property);
    flowDesign.setNodeRemarks(remark);




    $('#propertyForm').height($('body').height()-43);
    $('#propertyForm').css('max-height',$('body').height()+2000)
    $('#propertyForm').css('right',-$('#propertyForm').width()-12)
    // $('#propertyForm').css('box-shadow','none')
    $('.btnstorage').css('right',-$('.btnstorage').width())
    // $('.btnstorage').css('right',-$('.btnstorage').width())



    $('.closebtns').click(function () {
        $('#propertyForm').css('right',-$('#propertyForm').width()+12)
        $('.btnstorage').css('right',-$('.btnstorage').width())
        // $('.showAndHide').hide();
    })
    $('.setUpThe').click(function (event) {
        var me=this;
        if(!$(this).hasClass('theTrigger')){
            $(this).next('.candidatesUl').siblings('.candidatesUl').stop().slideUp(350);
            $(this).next('.candidatesUl').slideToggle(350);
        }
        if($(this).hasClass('active')){
            $(this).removeClass('active')
        }else {
            $(this).addClass('active');
        }
        $(me).siblings().removeClass('active');
        event.stopPropagation();
    })

    $('.dropDownDiv .candidatesPTwo').on('click',function (event) {
        $(this).next().stop().slideToggle(350)
        event.stopPropagation();
    })
    $('.dropDownDiv .dropDown li').on('click',function (event) {
        $(this).parent().stop().slideUp(350);
        $(this).parent().parent().find('input[type=text]').val($(this).find('span').text())
        $(this).parent().parent().find('input[type=hidden]').val($(this).find('input').val())
        event.stopPropagation();
    })
    $('.theCandidates').on('click',function () {

        var num=$(this).attr('data-num')
        if(num==1) {
            user_id = $(this).parent().siblings('textarea').prop('id');
            $.popWindow("../common/selectUser");
        }else if(num==2){
            dept_id=$(this).parent().siblings('textarea').prop('id');
            if($(this).hasClass('deptname')){
                $.popWindow("../common/selectDept?0");
            }else{
                $.popWindow("../common/selectDept?allDept=1");
            }
        }else if(num==3){
            priv_id=$(this).parent().siblings('textarea').prop('id');
            $.popWindow("../common/selectPriv");
        }
    })
    $('.addUserOp').click(function(){
        var topdefault = $(this).attr('topdefault');
        UserItemMain = 'autoUserOpReturn';
        UserItem = 'autoUserReturn';
        // var option = flowSelectAutoList[pid];
        allprcsUserlist = '';
        prcsPrivlist = '';
        prcsUserlist = '';
        prcsDeptlist = '';
        $.popWindow("/common/selectUserWorkFlowNew?topdefault=0&flowId="+flowstr+"&deptNo=&flowPrcs="+$('.returnStep').val());
    })
    $('.delectAuto').click(function(){
        $('#autoUserOpReturn').val('')
        $('#autoUserReturn').val('')
        $('#autoUserOpReturn').attr('user_id','')
        $('#autoUserReturn').attr('user_id','')
        $('[name="autoUserOpReturn"]').val('')
        $('[name="autoUserReturn"]').val('')
    })

    $('.xuanzezhuban').click(function () {
        // user_id='xuanzezhuban';
        // $.popWindow("../common/selectUser?0");
        UserItemMain = 'xuanzezhuban';
        UserItem = 'specifyTheHost';
        prcsPrivlist = [];
        prcsUserlist = [];
        prcsDeptlist = [];

        $.popWindow("../../common/selectUserWorkFlowNew?flowId="+ flowstr +"&deptNo=&flowPrcs="+$('[name="prcsId"]').val());
    })

    $('.qingchuzhuban').click(function () {
        $('#xuanzezhuban').val('').next().val('');
        $('#xuanzezhuban').attr('username','')
        $('#xuanzezhuban').attr('dataid','')
        $('#xuanzezhuban').attr('user_id','')
        $('#xuanzezhuban').attr('userprivname','')
        if($('#selectlayerthis .layui-anim-upbit .layui-this').attr('lay-value') == 3){
            $(this).parent().find('.theControlData').val('').attr({
                'user_id':'',
                'dataid':''
            }).next().val('');
        }
    })


    layui.use(['layer', 'form'], function(){
        layer = layui.layer
            ,form = layui.form();
        formTwo=form;
        theTriggersTwo()
        theTriggerchufa()
        ajaxSvg();
        form.on('select(candidatesfilters)', function(data){
            // console.log(data.elem); //得到select原始DOM对象
            // console.log(data.value); //得到被选中的值
            // console.log(data.othis); //得到美化后的DOM对象
            if(data.value==6){
                $(data.elem).parent().siblings('div').hide();
                $('.departmentAgent').show()
            }else if(data.value==9){
                $(data.elem).parent().siblings('div').hide();
                $('.auxiliaryDepartmentAgent').show()
            }else if(data.value==7){
                $(data.elem).parent().siblings('div').hide();
                $('.theSpecifiedRole').show()
            }else if(data.value==11){
                $(data.elem).parent().siblings('div').hide();
                $('.assignRole').show()
            }else {
                $(data.elem).parent().siblings('div').hide();
            }

        });

        form.on('select(prcsType)', function(data){
            if(data.value==1){
                $('.setUpThe').hide();
                $('.setUpThe').eq(0).show();
                $('.setUpThe').eq(2).show();
                $('.setUpThe').eq(7).show();
                $('.setUpThe').eq(10).show();
                $('.step').hide()
                $('.flowChild').show()
                var obj={};
                stris='新建流程'

                obj.flowId=$('[name="childFlow"]').val()
                obj.father=$('[name="relationIn"]').val()
                obj.child=$('[name="relationOut"]').val()
                obj.str='确定'
                obj.disabled = true
                obj.id = ""
                dataType = 1
                layer.open({
                    title: '子流程节点',
                    area: ['800px', '570px'],
                    type:1,
                    content: '<form id="saveRule" action="'+obj.url+'" class="layui-form"><div class="inputlayout">' +
                    '<ul>' +

                    '<li class="clearfix">' +
                    '<label>子流程类型 ：</label>' +
                    /*' <select name="module" data-value="'+obj.flowId+'"  lay-verify=""  lay-filter="process" >'+
                    '<option value="">请选择</option>'+
                    '</select>   ' +*/
                     '<div class="nameBox" style="position: relative;display: inline-block;width: 300px;margin-left: 30px;">\n' +
                        '<input data-value="'+obj.flowId+'" type="text" name="flowName" placeholder="全部流程" dataType="" style="width: 100%; height: 30px;padding-left: 5px;margin: 0;box-sizing: border-box;">\n' +
                        ' <div  class="listDown"><img style="margin-left: 15px" src="../../img/workflow/work/xiala.png" alt=""></div>\n' +
                        '<ul class="sel" style="z-index: 999; display: none;"></ul>\n' +
                        '</div>'+
                    '</li>' +

                    '<li class="clearfix" style="position: relative;padding-bottom: 50px">' +
                    '<label>关联 ：</label>' +
                    '<ul class="business allacti"  ></ul>' +
                    '<ul class="processS allacti" ></ul>' +
                    '<button class="btnSave" type="button" data-type="0" style="position: absolute;left: 30%;margin-left: -80px;bottom: 7px;color:#fff;' +
                    'background-color: #ccc;padding: 5px 10px;border-radius: 20px;cursor: pointer">添加父-子映射</button>' +
                    '<button class="btnSave" type="button" data-type="1" style="position: absolute;left: 70%;margin-left: -80px;bottom: 7px;color:#fff;' +
                    'background-color: #ccc;padding: 5px 10px;border-radius: 20px;cursor: pointer">添加子-父映射</button>' +
                    '</li>' +
                    '<li class="clearfix">' +
                    '<label>父->子流程映射关系 ：</label>' +
                    '<ol class="father">' +
                    '</ol>' +
                    '</li>' +
                    '<li class="clearfix" style="display: none">' +
                    '<label>子->父流程映射关系 ：</label>' +
                    '<ol class="child">' +
                    '</ol>' +
                    '</li>' +

                    '</ul>' +
                    '</div><input type="hidden" name="mapping"><input type="hidden" name="mappingFormat"><input type="hidden" name="id" value="'+obj.id+'"></form>',
                    btn: [obj.str, '取消'],
                    yes: function (index) {
                        var arrayObj=$('.father [name="maps"]');
                        var arrayObjs=$('.child [name="maps"]');
                        var str=''
                        var strs=""
                        for(var i=0;i<arrayObj.length;i++){
                            str+=$(arrayObj[i]).val()+','
                        }
                        for(var i=0;i<arrayObjs.length;i++){
                            strs+=$(arrayObjs[i]).val()+','
                        }
                        // $('[name="childFlow"]').val($('[name="module"]').val())
                        $('[name="childFlow"]').val($('input[name="flowName"]').attr('datatype'))
                        $('[name="relationIn"]').val(str)
                        $('[name="relationOut"]').val(strs)
                        layer.close(index)


                    },
                    success:function () {
                        $('[name="status"]').val(obj.status)
                        form.render()
                        var hmoduletwo=$('[name="hmodule"]').attr('data-value');//业务模块回显
                        var business;//业务
                        var str='';
                        var processData;//流程

                        if(endReturn == 1){
                            $('.child').parent().show()
                            $('.btnSave').eq(1).show()
                            $('.btnSave').eq(0).css('left','30%')
                        }else{
                            $('.child').parent().hide()
                            $('.btnSave').eq(1).hide()
                            $('.btnSave').eq(0).css('left','50%')
                        }
                        $.ajax({
                            url:"/flow/selOneToAllType",
                            type:'post',
                            dataType:'json',
                            success:function(res){
                                var data=res.datas;
//                console.log(data)
                                var str='<option value=""><fmt:message code="hr.th.PleaseSelect"/></option>';
                                if(res.flag){
                                    $.each(data,function(i,item){
                                        $('.sel').append("<li class='ones f_li' style='font-weight:bold;font-size:14px;text-align: initial;' id="+item.sortId +"><img src='../../img/data_points.png' style='margin-right: 5px;margin-top: -2px;' alt=''>" + item.sortName + "<li>");
                                        $.each(item.flowTypeModels,function(j,v){
                                            $('.sel').append("<li style='padding-left:10px;cursor:pointer;text-align: initial;' class='canchoose' value="+v.flowId +">" +v.flowName + "<li>");
//                                $('[name="dispatchType"]').append("<option value="+v.flowId +">" + + "</option>");
                                        })
                                        buildNode(1,item.childs);
                                    });
                                    $('.canchoose').each(function (i,n) {
                                        if($(this).attr('value')==$('[name="flowName"]').attr('data-value')){
                                            $(this).click();
                                            return false;
                                        }
                                    });
                                }
                            }
                        })
                       /* $.get('/flowSort/getFlowTypes',{'sonType':'1'},function (json) {
                            if(json.flag){
                                var arrobj=json.obj;
                                for(var i=0;i<arrobj.length;i++){
                                    str+='<optgroup label="'+arrobj[i].sortName+'">' +
                                        ''+function () {
                                            var stroption='';
                                            for(var m=0;m<arrobj[i].flowTypeModels.length;m++){
                                                stroption+='<option value="'+arrobj[i].flowTypeModels[m].flowId+'">' +
                                                    ''+arrobj[i].flowTypeModels[m].flowName+'</option>'
                                            }
                                            return stroption;
                                        }()+'</optgroup>'
                                }
                                $('[name="module"]').append(str)
                                form.render()
                                $('[name="module"]').next().find('dd').each(function (i,n) {
                                    if($(this).attr('lay-value')==$('[name="module"]').attr('data-value')){
                                        $(this).click();
                                        return false;
                                    }
                                });
                            }
                        },'json')*/
                        $('[name="dataDirection"]').next().find('dd').each(function (i,n) {
                            if($(this).attr('lay-value')==$('[name="dataDirection"]').attr('data-value')){
                                $(this).click();
                                return false;
                            }
                        })

                        if(obj.father!=undefined&&obj.father!="") {
                            var arraythr = obj.father.split(',');
                            var strthree = '';
                            for (var q = 0; q < arraythr.length; q++) {
                                if (q != arraythr.length - 1) {
                                    strthree += '<li><span>' + arraythr[q] + '</span><input type="hidden" name="maps" value="' + arraythr[q] + '"><b>x</b></li>'
                                } else if (arraythr.length == 1) {
                                    strthree += '<li><span>' + arraythr[q] + '</span><input type="hidden" name="maps" value="' + arraythr[q] + '"><b>x</b></li>'
                                }
                            }
                            $('.father').html(strthree)
                        }

                        if(obj.child!=undefined&&obj.child!="") {
                            var arraythrs = obj.child.split(',');
                            var strthrees = '';
                            for (var q = 0; q < arraythrs.length; q++) {
                                if (q != arraythrs.length - 1) {
                                    strthrees += '<li><span>' + arraythrs[q] + '</span><input type="hidden" name="maps" value="' + arraythrs[q] + '"><b>x</b></li>'
                                } else if (arraythrs.length == 1) {
                                    strthrees += '<li><span>' + arraythrs[q] + '</span><input type="hidden" name="maps" value="' + arraythrs[q] + '"><b>x</b></li>'
                                }
                            }
                            $('.child').html(strthrees)
                        }

                        //获取流程名称
                        $.ajax({
                            url:'/reportSettings/querybyFlowIdField',
                            dataType:'json',
                            type:'get',
                            data:{'flowId':flowstr},
                            success:function(res){
                                var data = res.obj[0].printModel;
                                var str='';
                                var obj=[];

                                var len = $(data).find('.form_item').length
                                for(var i = 0;i<len;i++){
                                    str+='<li>'+$(data).find('.form_item').eq(i).attr('title')+'<input type="hidden" value="'+$(data).find('.form_item').eq(i).attr('id')+'"></li>'
                                    obj.push($(data).find('.form_item').eq(i))
                                }
                                str += '<li>流程附件<input type="hidden" value=""></li>';
                                $.ajax({
                                    type: 'get',
                                    url: '/flowSort/selectType',
                                    dataType: 'json',
                                    data: {'flowId':flowstr},
                                    async: false,
                                    success: function(res) {
                                        if (res.flag && res.code == 0) {
                                            str += '<li>公文正文<input type="hidden" value=""></li>';
                                        }
                                    }
                                });
                                business = obj;
                                if(dataType == 1){
                                    $('.business').html(str)
                                }else{
                                    $('.processS').html(str)
                                }


                                // $('[name="dataDirection"]').val(res.obj[0].formName+'-')
                                flowName = res.obj[0].formName
                            }
                        })


                        /*form.on('select(process)',function (data) {//流程
                            $.post('/flowhook/queryFormId',{'folwId':data.value},function (json) {
                                if(json.flag){
                                    workForm.init({
                                            formhtmlurl: '../../form/formType',
                                            resdata: {
                                                fromId: json.object.formId
                                            },
                                            flag: 3
                                        },
                                        function (datas) {
                                            processData = datas;
                                            var liStrs='';//流程

                                            for(var m=0;m<processData.length;m++){
                                                liStrs+='<li>'+processData[m].title+'<input type="hidden" value="'+processData[m].name+'"></li>'
                                            }
                                            liStrs +='<li>流程附件<input type="hidden" value=""></li>';
                                            $.ajax({
                                                type: 'get',
                                                url: '/flowSort/selectType',
                                                dataType: 'json',
                                                data: {'flowId': data.value},
                                                async: false,
                                                success: function(res) {
                                                    if (res.flag && res.code == 0) {
                                                        liStrs += '<li>公文正文<input type="hidden" value=""></li>';
                                                    }
                                                }
                                            });
                                            var strOption = '<option value="1">'+flowName+'-'+json.object.flowName+'</option><option value="2">'+json.object.flowName+'-'+flowName+'</option>'
                                            $('[name="dataDirection"]').html(strOption)

                                            $('[name="dataDirection"]').val(dataType)
                                            form.render();
                                            if($('[name="dataDirection"]').val()==1){
                                                $('.processS').html(liStrs)
                                            }else if($('[name="dataDirection"]').val()==2){
                                                $('.business').html(liStrs)
                                            }else{
                                                $('.processS').html(liStrs)
                                            }
                                        });
                                }
                            },'json')
                        })*/





                        $(document).delegate('.allacti>li','click',function () {
                            $(this).parent().find('li').removeClass('active')
                            $(this).addClass('active')
                        })

                        $('.btnSave').click(function () {
                            var type=$(this).attr('data-type')

                            var textBusiness=$('.business .active').text()
                            var inVBusiness=$('.business .active').find('input').val()
                            var textprocessS=$('.processS .active').text()
                            var inprocessS=$('.processS .active').find('input').val()
                            if(textBusiness==''||textprocessS==''){
                                alert('请选择子流程和父流程字段')
                                return false
                            }
                            var arrAus=$('.father li');
                            var arrAuss = $('.child li')
                            var trueNum=null;

                            if(type == 0){
                                for(var i=0;i<arrAus.length;i++){
                                    console.log($(arrAus[i]).find('input').val())
                                    if($(arrAus[i]).find('input').val()==(textBusiness+'=>'+textprocessS)){
                                        alert('该映射关系已存在')
                                        trueNum=1;
                                        return false
                                    }
                                }
                            }else{
                                for(var j=0;j<arrAuss.length;j++){
                                    if($(arrAuss[j]).find('input').val() == (textprocessS+'=>'+textBusiness)){
                                        alert('该映射关系已存在')
                                        trueNum=1;
                                        return false
                                    }
                                }
                            }


                            if(trueNum==1){
                                return
                            }
                            var str='';
                            // $('[name="dataDirection"]').val(dataType)
                            // if($('[name="dataDirection"]').val()==1) {
                            //     str = '<li><span>' + $('.business .active').text() + '-' + $('.processS .active').text() +'</span><input type="hidden" name="maps" value="' + ($('.business .active').find('input').val()+'=>'+$('.processS .active').find('input').val()) + '"><b>x</b></li>'
                            // }else if($('[name="dataDirection"]').val()==2){
                            //     str = '<li><span>' + $('.business .active').text() + '-' + $('.processS .active').text() + '('+$('[name="dataDirection"] option:selected').text()+')</span><input type="hidden" name="maps" value="' + ($('.business .active').find('input').val()+'=>'+$('.processS .active').find('input').val()) + '"><b>x</b></li>'
                            // }
                            if(type == 0){
                                str = '<li><span>' + $('.business .active').text() + '-' + $('.processS .active').text() +'</span><input type="hidden" name="maps" value="' + ($('.business .active').text()+'=>'+$('.processS .active').text()) + '"><b>x</b></li>'
                                $('.father').append(str)
                            }else{
                                str = '<li><span>' + $('.processS .active').text() + '-' + $('.business .active').text() +'</span><input type="hidden" name="maps" value="' + ($('.processS .active').text()+'=>'+$('.business .active').text()) + '"><b>x</b></li>'
                                $('.child').append(str)
                            }

                        })

                        $(document).delegate('.inputlayout ol li b','click',function () {
                            $(this).parent().remove()
                        })

                    }
                })
            }else{
                $('.setUpThe').show();
                $('.step').show()
                $('.flowChild').hide()
                $('.flowChilds').hide()
                $('input[name="childFlow"]').val(0)
                $('input[name="relationIn"]').val('')
                $('input[name="relationOut"]').val('')
                $('input[name="autoUserOpReturn"]').val('')
                $('input[name="autoUserReturn"]').val('')
                $('#autoUserOpReturn').val('')
                $('#autoUserReturn').val('')

            }

        });
        //监听子流程类型
        $(document).on('click','.listDown',function(e){
            if( $('.sel').css('display')!='none'){
                $('.sel').hide()
            }else{
                $('.sel').show()
            }
            e.stopPropagation()
        })
        function buildNode(len,data){
            var prefix = 10;
            for(var i=0;i<len;i++){
                prefix += 10;
            }

            $.each(data,function(i,item){
                if(0 < item.childs.length){
                    $('.sel').append("<li class='f_li' style='padding-left:"+(prefix)+"px;font-weight:bold;font-size:14px;' id="+item.sortId +">" + item.sortName + "<li>");
                    $.each(item.flowTypeModels,function(j,v){
                        $('.sel').append("<li style='padding-left:"+(prefix+10)+"px;cursor:pointer;text-align: initial;' class='canchoose' value="+v.flowId +">" +  v.flowName + "<li>");
                    })
                    buildNode(len+1,item.childs);
                }else{
                    $('.sel').append("<li class='f_li' style='padding-left:"+(prefix)+"px;font-weight:bold;font-size:14px;' id="+item.sortId +">" + item.sortName + "<li>");
                    $.each(item.flowTypeModels,function(j,v){
                        $('.sel').append("<li style='padding-left:"+(prefix+10)+"px;cursor:pointer;text-align: initial;' class='canchoose' value="+v.flowId +">" +  v.flowName + "<li>");
                    })
                }
            });
        }
        $(document).click(function(){
            $('.sel').hide()
        })
        $(document).on('keyup','input[name="flowName"]',function(){
            $('.sel').show()
            var val=$(this).val()
            $('.sel li').each(function(i,v){
                if(v.innerHTML.indexOf(val)>-1){
                    $(v).show();
                    $(v).parent().show()
                }else{
                    $(v).hide();
                }
            })
        })
        $(document).on('click','.sel li',function(e){
            e.stopPropagation()
            if($(this).attr('value')){
                $('[name="flowName"]').val($(this).html())
                $('[name="flowName"]').attr('dataType',$(this).attr('value'))
                $('.sel').hide()
            }else{
                $('.sel').show()
            }
            //子流程类型改变后关联值对应变化
            $.post('/flowhook/queryFormId',{'folwId':$(this).attr('value')},function (json) {
                if(json.flag){
                    workForm.init({
                            formhtmlurl: '../../form/formType',
                            resdata: {
                                fromId: json.object.formId
                            },
                            flag: 3
                        },
                        function (datas) {
                            processData = datas;
                            var liStrs='';//流程

                            for(var m=0;m<processData.length;m++){
                                liStrs+='<li>'+processData[m].title+'<input type="hidden" value="'+processData[m].name+'"></li>'
                            }
                            liStrs +='<li>流程附件<input type="hidden" value=""></li>';
                            $.ajax({
                                type: 'get',
                                url: '/flowSort/selectType',
                                dataType: 'json',
                                data: {'flowId': $(this).attr('value')},
                                async: false,
                                success: function(res) {
                                    if (res.flag && res.code == 0) {
                                        liStrs += '<li>公文正文<input type="hidden" value=""></li>';
                                    }
                                }
                            });
                            var strOption = '<option value="1">'+flowName+'-'+json.object.flowName+'</option><option value="2">'+json.object.flowName+'-'+flowName+'</option>'
                            $('[name="dataDirection"]').html(strOption)

                            $('[name="dataDirection"]').val(dataType)
                            form.render();
                            if($('[name="dataDirection"]').val()==1){
                                $('.processS').html(liStrs)
                            }else if($('[name="dataDirection"]').val()==2){
                                $('.business').html(liStrs)
                            }else{
                                $('.processS').html(liStrs)
                            }
                        });
                }
            },'json')

        })

        form.on('radio(endReturn)',function (data) {
            if(data.value == 0){
                endReturn = 0
                $('.flowChilds').hide();
            }else{
                endReturn = 1
                $('.flowChilds').show();
            }
        })
        
        
        form.on('radio(feedbackS)',function (data) {

            if(data.value==1){

                $(data.elem).parent().parent().parent().next().hide();
                var arr=$(data.elem).parent().parent().parent().next().find('input')
                for(var i=0;i<arr.length;i++){
                    $(arr[i]).attr('checked',false)
                }
                form.render()

            }else {
                $(data.elem).parent().parent().parent().next().show();
                form.render()
            }
            
        })
        form.on('select(automaticCandidateTwo)', function(data){
            // console.log(data.elem); //得到select原始DOM对象
            // console.log(data.value); //得到被选中的值
            // console.log(data.othis); //得到美化后的DOM对象
            if(data.value==2||data.value==9||data.value==4||data.value==6||data.value==5||data.value==10||data.value==11){
                $(data.elem).parent().siblings('div').hide();
                $('.autoBaseUser').show();
            }else if(data.value==12||data.value==13||data.value==14||data.value==15){
                $(data.elem).parent().siblings('div').hide();
                $('.optionalDepartmentAgent').show()
            }else if(data.value==3){
                $(data.elem).parent().siblings('div').hide();
                $('.specifyTheHost').show()
            }else if(data.value==7){
                $(data.elem).parent().siblings('div').hide();
                $('.oneTheHost').show()
            }else if(data.value==8){
                $(data.elem).parent().siblings('div').hide();
                // $('.stepsTwos').show()
                $('.autoBaseUser').show();
            }else {
                $(data.elem).parent().siblings('div').hide();
            }
        });


                 //自动归档设置

                $('#guidang').click(function () {
                layer.open({
                    type: 1 //Page层类型
                    ,area: ['650px', '630px']
                    ,title: '自动归档设置'
                    ,content: '<form class="guidang_form inputlayout">' +
                        '<div>' +
                        '<div style="margin-top: 5px;margin-left: 30px" id="yrn"><span>是否自动归档：</span><input type="radio" id="guidang1" name="guidang" value="0" style="margin-left: 15px" checked="true">不自动归档<input id="guidang2" type="radio" name="guidang" value="1" style="margin-left: 10px">强制自动归档</div>' +
                        '<div style="margin-top: 20px;margin-left: 30px"><span>归档于：</span> ' +
                        '<span style="margin-left: 38px">卷库</span> <select name="room" id="room" style="width: 150px" lay-filter="process" ></select>' +
                        '<span style="margin-left: 15px">案卷</span> <select name="roll" id="roll" style="width: 150px" lay-filter="process" ><option value="" >请选择</option></select>' +
                        '</div>' +
                        '<div style="margin-top: 20px;margin-left: 30px" id="anguize"><span>案卷规则：</span> <span style="margin-left: 25px">自动克隆案卷</span>' +
                        '<input id="guize1" type="checkbox" name="guize" value="1" style="margin-left: 15px">（规则为当前案卷名称+年份）' +
                        ' </div>' +
                        '<div style="margin-top: 70px;margin-left: 30px">' +
                        '<p>字段映射选项：</p>' +
                        '</div>' +
                        '<div style="margin-top:-80px;margin-left: 100px" >' +
                        '<ul class="business allacti inputlayout" style="float: left;margin-left: 30px;height: 130px;max-height: 300px;overflow:auto;border: 1px solid #ddd;border-radius: 4px;width: 133px;"></ul>' +
                        '<ul class="processS allacti inputlayout" style="float: left;margin-left: 30px;height: 130px;max-height: 300px;overflow:auto;border: 1px solid #ddd;border-radius: 4px;width: 133px;">' +
                        '<li style="margin-left:5px;cursor:pointer;" >文件号</li>' +
                        '<li style="margin-left:5px;cursor:pointer;" >文件主题词</li>' +
                        '<li style="margin-left:5px;cursor:pointer;" >文件标题</li>' +
                        '<li style="margin-left:5px;cursor:pointer;" >文件辅标题</li>' +
                        // '<li style="margin-left:5px;cursor:pointer;" >发文单位</li>' +
                        // '<li style="margin-left:5px;cursor:pointer;" >发文日期</li>' +
                        // '<li style="margin-left:5px;cursor:pointer;" >密级</li>' +
                        // '<li style="margin-left:5px;cursor:pointer;" >紧急等级</li>' +
                        // '<li style="margin-left:5px;cursor:pointer;" >文件分类</li>' +
                        // '<li style="margin-left:5px;cursor:pointer;" >公文类别</li>' +
                        '<li style="margin-left:5px;cursor:pointer;" >文件页数</li>' +
                        '<li style="margin-left:5px;cursor:pointer;" >打印页数</li>' +
                        '<li style="margin-left:5px;cursor:pointer;" >备注</li>' +
                        // '<li style="margin-left:5px;cursor:pointer;" >所属案卷</li>' +
                        '</ul>' +
                        '</div>' +
                        '<div style="margin-top: 150px;margin-left:220px"><button class="btnSsave" type="button"  style="left: 50%;bottom: 7px;color:#fff;background-color: #ccc;padding: 5px 10px;border-radius: 20px;cursor: pointer;margin-left:-35px;">添加流程 - 档案文件字段映射</button></div>' +
                        '<div style="margin-top: 40px;margin-left: 30px"><p style="margin-top: 50px">字段映射规则:</p></div>' +
                        '<div style="margin-top: -60px;margin-left: 100px">' +
                        '<ol id="oll" class="father" style="float: left;margin-left: 30px;height: 100px;max-height: 300px;border: 1px solid #ddd;border-radius: 4px;width: 300px;overflow:auto;">' +
                        '<li style="margin-left: 85px;margin-top: 20px"><span id="baioqian"></span></li>' +
                        '</ol>' +
                        '</div>' +
                        '<div style="margin-top: 120px;margin-left: 30px" id="nr"><span>归档内容：</span> <input type="checkbox" style="margin-left: 25px" value="0" name="smstype" id="zhengwen">正文<input type="checkbox" style="margin-left: 10px" value="1" name="smstype" id="fujian">附件<input type="checkbox" style="margin-left: 10px" value="2" name="smstype" id="biaodan">表单' +
                        '</div>' +
                        '</div>' +
                        '</form>'
                        // <input type="checkbox" style="margin-left: 10px" value="3" name="smstype" id="yasuo">三者压缩


                    ,btn:['确定','取消']
                    , success: function (res) {
                        $(document).delegate('.allacti>li','click',function () {
                            $(this).parent().find('li').removeClass('active')
                            $(this).addClass('active')
                        })
                        // 获取卷库列表
                        $.get('/rmsRollRoom/selectAll',function (res) {
                            if (res.flag && res.obj.length > 0) {
                                var str='<option value="">请选择</option>';
                                res.obj.forEach(function(item){
                                    str+='<option value="'+item.roomId+'">'+item.roomName+'</option>'
                                })
                                $('#room').append(str)

                                $('#room').val(rmsRollRoom);

                                if(rmsRollRoom){

                                    $.get('/rmsRoll/query',{roomId: rmsRollRoom}, function (res) {
                                        var str='';
                                        if (res.flag && res.obj.length > 0) {
                                            res.obj.forEach(function(item){
                                                str+='<option value="'+item.rollId+'">'+item.rollName+'</option>'
                                            });
                                        }

                                        $('#roll').append(str);

                                        $('#roll').val(rmsRoll);
                                    });
                                }
                            }
                        });

                        // 选择卷库后获取对应案卷列表
                        $('#room').on('change', function(){
                            console.log($(this).val())
                            var roomId = $(this).val();
                            $('#roll').empty();
                            var str='<option value="">请选择</option>';
                            if (roomId && roomId != '') {
                                $.get('/rmsRoll/query',{roomId: roomId}, function (res) {
                                    if (res.flag && res.obj.length > 0) {
                                        res.obj.forEach(function(item){
                                            str+='<option value="'+item.rollId+'">'+item.rollName+'</option>'
                                        });
                                    }
                                    $('#roll').append(str);
                                });
                            } else {
                                $('#roll').append(str);
                            }
                        });

                        $(document).delegate('.inputlayout ol li b','click',function () {
                            $(this).parent().remove()
                        })

                        //字段映射选项
                        //获取流程名称
                        $.ajax({
                            url:'/reportSettings/querybyFlowIdField',
                            dataType:'json',
                            type:'get',
                            data:{'flowId':flowstr},
                            success:function(res){
                                var data = res.obj[0].printModel;
                                var str='';
                                var obj=[];

                                var len = $(data).find('.form_item').length
                                for(var i = 0;i<len;i++){
                                    str+='<li style="margin-left:5px;cursor:pointer;" >'+$(data).find('.form_item').eq(i).attr('title')+'<input type="hidden" value="'+$(data).find('.form_item').eq(i).attr('id')+'"></li>'
                                    obj.push($(data).find('.form_item').eq(i))
                                }
                                str += '<li style="margin-left:5px">流程附件<input type="hidden" value=""></li>';
                                $.ajax({
                                    type: 'get',
                                    url: '/flowSort/selectType',
                                    dataType: 'json',
                                    data: {'flowId':flowstr},
                                    async: false,
                                    success: function(res) {
                                        if (res.flag && res.code == 0) {
                                            str += '<li style="margin-left:5px">公文正文<input type="hidden" value=""></li>';
                                        }
                                    }
                                });
                                    $('.business', $('.guidang_form')).html(str)
                            }
                        })


                        //添加父子映射

                        $('.btnSsave').click(function () {

                            var textBusiness=$('.business .active').text()
                            var inVBusiness=$('.business .active').find('input').val()
                            var textprocessS=$('.processS .active').text()
                            var inprocessS=$('.processS .active').find('input').val()
                            if(textBusiness==''||textprocessS==''){
                                alert('请选择子流程和父流程字段')
                                return false
                            }
                            var arrAus=$('.father li');
                            var arrAuss = $('.child li')
                            var trueNum=null;
                            for(var i=0;i<arrAus.length;i++){
                                console.log($(arrAus[i]).find('input').val())
                                if($(arrAus[i]).find('input').val()==(textBusiness+'=>'+textprocessS)){
                                    alert('该映射关系已存在')
                                    trueNum=1;
                                    return false
                                }
                            }

                            if(trueNum==1){
                                return
                            }
                            var str='';

                            str = '<li style="margin-left: 88px;margin-top:2px"><span>' + $('.business .active').text() + '=>' + $('.processS .active').text() +'</span><input type="hidden" name="maps" value="' + ($('.business .active').text()+'=>'+$('.processS .active').text()) + '"><b style="color: red;cursor:pointer;">x</b></li>'
                            $('.father').append(str)


                        })




                        //数据回显
                        // str = '<b id="lb" style="color: red;cursor:pointer;">x</b>'

                        if(mappingRule) {
                            var str='';
                            var rule = mappingRule.split(',')
                            for (i = 0; i < rule.length; i++) {
                                if (rule[i]) {
                                    str += '<li style="margin-left: 88px;margin-top:5px"><span>' + rule[i] + '</span><input type="hidden" name="maps" value="' + rule[i] + '"><b style="color: red;cursor:pointer;">x</b></li>'
                                }
                            }
                        }else {
                           return null
                        }
                        $('#oll').append(str);







                        if(file==0){
                            $("#guidang1").attr("checked",true)
                            $("#guidang2").attr("disabled",false)
                        }
                        if(file==1){
                            $("#guidang1").attr("checked",false)
                            $("#guidang2").attr("checked",true)
                        }
                        if(fileRule==1){
                            $("#guize1").attr("checked","checked")
                        }

                        $(fileContent.split(",")).each(function (i,e){
                            $("input[name='smstype'][value='"+e+"']").prop("checked",true);
                        });





                    }
                    , yes: function (index) {
                        //获取参数

                        // var groupCheckbox=$("input[name='smstype']");
                        // for(i=0;i<groupCheckbox.length;i++){
                        //     if(groupCheckbox[i].checked){
                        //        val =groupCheckbox[i].value;
                        //     }
                        // }
                        var files = $('input[name="guidang"]:radio:checked', $('#yrn')).val();
                        var  fileContents=''
                        var $fileContents = $('input[name="smstype"]:checkbox:checked', $('#nr'));
                        $fileContents.each(function(){
                             fileContents += $(this).val() + ',';
                        });

                        var fileRules = $('input[name="guize"]:checkbox:checked', $('#anguize')).val();
                         var rmsRollRooms = $("#room").val();
                         var rmsRolls = $("#roll").val();
                         var mappingRules=''
                         var  $mappings = $('input', $('#oll'));
                        $mappings.each(function(){
                            mappingRules += $(this).val() + ',';
                        });

                        if(rmsRollRooms=='' || rmsRolls==''){
                            alert('请选择：卷库/案卷！')
                        }


                        var obj={
                            file:files,
                            fileContent:fileContents,
                            fileRule:fileRules,
                            rmsRollRoom:rmsRollRooms,
                            rmsRoll:rmsRolls,
                            mappingRule:mappingRules
                        }
                       var  autoArchiveSet = JSON.stringify(obj)

                        console.log(autoArchiveSet)

                        $('[name="autoArchiveSet"]').val(autoArchiveSet);

                        layer.close(index)


                    }
                });



            })

        $('.bottomsteps').click(function () {


            var str='';
            var laystr=''
            if($(this).attr('data-field')==0) {
                for (var i = 0; i < dataToAll.length; i++) {
                    str += '<input type="checkbox" title="'+ dataToAll[i].prcsId +'.'+ dataToAll[i].prcsName + '" value="' + dataToAll[i].prcsId + '"  lay-filter="divAllData">'
                }
                laystr='<div class="bottomstepstwo layui-form" style="margin: 10px ;" value="'+ $(this).next('input[name=prcsTo]').val() +'"><div class="divAllData layui-form">'+str+ '<input type="checkbox" title="结束" value="0" lay-filter="divAllData"></div><div style="margin-top: 15px;" id="checkAll"><span><input type="checkbox" class="checkedAll" title="全选"></span> </div>'+
                    '</div>'
            }else if($(this).attr('data-field')==1 ){
                if(alertData==undefined){
                    $.layerMsg({content:'正在保存表单，即将刷新！',icon:6},function(){
                        location.reload()
                    });
                }
                if($(this).siblings('input[type=hidden]').val()!=''){
                    var hiddenItemArr=$(this).siblings('input[type=hidden]').val().split(',');
                    for(var i=0;i<alertData.length;i++) {
                        for (var n = 0; n < hiddenItemArr.length; n++) {
                            if (alertData[i].title == hiddenItemArr[n]) {
                                var strTwo = '<input type="checkbox" checked title="' + alertData[i].title + '" value="' + alertData[i].name + '">'
                                break;
                            } else {
                                var strTwo = '<input type="checkbox" title="' + alertData[i].title + '" value="' + alertData[i].name + '">'
                            }
                        }
                            str+=strTwo;
                    }
                }else {
                    for(var i=0;i<alertData.length;i++) {
                        str += '<input type="checkbox" title="' + alertData[i].title + '" value="' + alertData[i].name + '">'

                    }
                }
                laystr='<div class="bottomstepstwo layui-form" style="margin: 10px ;"><div class="divAllData">'+str+ '</div><div style="margin-top: 15px;" id="checkAll"><span><input type="checkbox" class="checkedAll" title="全选"></span> </div>'+
                    '</div>'
            }else if( $(this).attr('data-field')==3){
                if(alertData==undefined){
                    $.layerMsg({content:'正在保存表单，即将刷新！',icon:6},function(){
                        location.reload()
                    });
                }
                if($(this).siblings('input[type=hidden]').val()!=''){
                    var hiddenItemArr=$(this).siblings('input[type=hidden]').val().split(',');
                    for(var i=0;i<alertData.length;i++) {
                        for (var n = 0; n < hiddenItemArr.length; n++) {
                            if (alertData[i].name == hiddenItemArr[n]) {
                                var strTwo = '<input type="checkbox" checked title="' + alertData[i].title + '" value="' + alertData[i].name + '">'
                                break;
                            } else {
                                var strTwo = '<input type="checkbox" title="' + alertData[i].title + '" value="' + alertData[i].name + '">'
                            }
                        }
                        str+=strTwo;
                    }
                }else {
                    for(var i=0;i<alertData.length;i++) {
                        str += '<input type="checkbox" title="' + alertData[i].title + '" value="' + alertData[i].name + '">'

                    }
                }
                laystr='<div class="bottomstepstwo layui-form" style="margin: 10px ;"><div class="divAllData">'+str+ '</div><div style="margin-top: 15px;" id="checkAll"><span><input type="checkbox" class="checkedAll" title="全选"></span> </div>'+
                    '</div>'
            } else if ($(this).attr('data-field')==2){
                if($(this).siblings('input[type=hidden]').val()!=''){
                    var hiddenItemArr=$(this).siblings('input[type=hidden]').val().split(',');
                    for(var i=0;i<operationData.length;i++) {
                        for (var n = 0; n < hiddenItemArr.length; n++) {
                            if (operationData[i].opName == hiddenItemArr[n]) {
                                var strTwo = '<input type="checkbox" checked title="' + operationData[i].opName + '" value="' + operationData[i].opId + '">'
                                break;
                            } else {
                                var strTwo = '<input type="checkbox" title="' + operationData[i].opName + '" value="' + operationData[i].opId + '">'
                            }
                        }
                        str+=strTwo;
                    }
                }else {
                    for(var i=0;i<operationData.length;i++) {
                        str += '<input type="checkbox" title="' + operationData[i].opName + '" value="' + operationData[i].opId + '">'

                    }
                }

                laystr='<div class="bottomstepstwo layui-form" style="margin: 10px ;"><div class="divAllData">'+str+ '</div><div style="margin-top: 15px;" id="checkAll"><span><input type="checkbox" class="checkedAll" title="全选"></span> </div>'+
                    '</div>'
            }
            var me=this;

        layer.open({
            type:1,
            title:$(me).parent().parent().prev().text(),
            content: laystr,
            area:['600px','400px'],
            btn:['确定','关闭'],
            resizing: function(layero){
                layero.find('.bottomstepstwo').css('height',layero.find('.layui-layer-content').height()-30+'px');
            },
            yes:function (index) {
                var str='';
                var strTwo='';
                var obj=$('.bottomstepstwo .divAllData input[type=checkbox]:checked');
                if($(me).attr('data-field')==0) {
                    var value = $('.bottomstepstwo.layui-form').attr('value').split(',');
                    for(var i =0;i<value.length;i++){
                        if(value[i] != ''){
                            obj.each(function (y,n) {
                                if($(this).val() == value[i]){
                                    strTwo+='<li>'+$(this).next().find('span').text()+'</li>'
                                }
                            })
                        }
                    }
                    $(me).nextAll('input').val($('.bottomstepstwo.layui-form').attr('value'));
                    $(me).parent().prev().html(strTwo);
                    layer.close(index);
                    return false;
                }else if($(me).attr('data-field')==1) {
                    obj.each(function (i,n) {
                        if(i<obj.length-1){
                            str+=$(this).attr('title')+','
                        }else {
                            str+=$(this).attr('title')+',';
                        }
                        strTwo+='<li>'+$(this).next().find('span').text()+'</li>'
                    })
                }else if($(me).attr('data-field')==3){
                    obj.each(function (i,n) {
                        if(i<obj.length-1){
                            str+=$(this).val()+','
                        }else {
                            str+=$(this).val()+',';
                        }
                        strTwo+='<li>'+$(this).next().find('span').text()+'</li>'
                    })
                }else if ($(me).attr('data-field')==2) {
                    obj.each(function (i, n) {
                        if (i < obj.length - 1) {
                            str += $(this).val() + ','
                        } else {
                            str += $(this).val() + ',';
                        }
                        strTwo += '<li>' + $(this).next().find('span').text() + ',</li>'
                    })
                }
                $(me).nextAll('input').val(str);
                $(me).parent().prev().html(strTwo)
                layer.close(index)
            },
            success:function () {
                if($(me).attr('data-field')==0) {
                    var arrayprcsTo=$('[name="prcsTo"]').val().split(',')
                    $('.divAllData [type="checkbox"]').each(function(i,n){
                        for(var m=0;m<arrayprcsTo.length;m++){
                            if($(this).val()==arrayprcsTo[m]){
                                $(this).prop('checked',true)
                            }
                        }
                    })
                }else if($(me).attr('data-field')==1){
                    var hiddenItemhide=$(me).next().val().split(',');
                    $('.divAllData [type="checkbox"]').each(function(i,n){
                        for(var m=0;m<hiddenItemhide.length;m++){
                            if($(this).val()==hiddenItemhide[m]){
                                $(this).prop('checked',true)
                            }
                        }
                    })

                }else if ($(me).attr('data-field')==2){
                    var arrayoperationButton=$('[name="operationButton"]').val().split(',')
                    $('.divAllData [type="checkbox"]').each(function(i,n){
                        for(var m=0;m<arrayoperationButton.length;m++){
                            if($(this).val()==arrayoperationButton[m]){
                                $(this).prop('checked',true)
                            }
                        }
                    })
                }
                form.render();
                if($(me).attr('data-field') == 0) {
                    form.on('checkbox(divAllData)', function(data){
                        var value = $('.bottomstepstwo.layui-form').attr('value').split(',');
                        if(value[value.length -1] == ''){
                            value.splice(value.length -1,1);
                        }
                        if(value.length == 0){
                            value.push($(data.elem).val());
                            var bottomstepstwoVlue = value.join(',')+',';
                            $('.bottomstepstwo.layui-form').attr('value',bottomstepstwoVlue);
                        }else{
                            for(var i =0;i<value.length;i++){
                                if($(data.elem).val() == value[i]){
                                    value.splice(i,1);
                                    var bottomstepstwoVlue = '';
                                    if(value.length != 0){
                                        var bottomstepstwoVlue = value.join(',')+',';
                                    }
                                    $('.bottomstepstwo.layui-form').attr('value',bottomstepstwoVlue);
                                    break;
                                }
                                if(i == value.length-1){
                                    value.push($(data.elem).val());
                                    var bottomstepstwoVlue = value.join(',')+',';
                                    $('.bottomstepstwo.layui-form').attr('value',bottomstepstwoVlue);
                                    break;
                                }
                            }
                        }

                    });
                }
            }
        })
    })

        $('.deleteTwo').click(function () {
            if($(this).parent().siblings('textarea').attr('user_id')!=undefined){
                $(this).parent().siblings('textarea').attr('user_id','')
                $(this).parent().siblings('textarea').attr('dataid','')
            }else if($(this).parent().siblings('textarea').attr('deptname')!=undefined){
                $(this).parent().siblings('textarea').attr('deptname','')
                $(this).parent().siblings('textarea').attr('deptid','')
                $(this).parent().siblings('textarea').attr('dataid','')
                $(this).parent().siblings('textarea').attr('deptno','')
            }else if($(this).parent().siblings('textarea').attr('userpriv')!=undefined){
                $(this).parent().siblings('textarea').attr('userpriv','')
            }else if($(this).parent().siblings('textarea').attr('privid')!=undefined){
                $(this).parent().siblings('textarea').attr('privid','')
            }
            $(this).parent().siblings('textarea').val('')
            $(this).parent().siblings('input').val('')
        })

        //条件设置与通达OA兼容方法
        function checkCondition(arrprcsIn){
            var prcsIn = ''
            if(arrprcsIn.indexOf('MAIN_USER_SIGN')>-1){
                prcsIn = arrprcsIn.replace(/MAIN_USER_SIGN/g,'主办人会签意见')
            }else if(arrprcsIn.indexOf('USER_SIGN')>-1){
                prcsIn= arrprcsIn.replace(/USER_SIGN/g,'经办人会签意见')
            }else if(arrprcsIn.indexOf('ATTACH_NAME')>-1){
                prcsIn=arrprcsIn.replace(/ATTACH_NAME/g,'公共附件名称')
            }else if(arrprcsIn.indexOf('ATTACH_COUNT')>-1){
                prcsIn=arrprcsIn.replace(/ATTACH_COUNT/g,'公共附件个数')
            }else if(arrprcsIn.indexOf('CUR_PRCS_ID')>-1){
                prcsIn=arrprcsIn.replace(/CUR_PRCS_ID/g,'当前步骤号')
            }else if(arrprcsIn.indexOf('CUR_FLOW_PRCS')>-1){
                prcsIn=arrprcsIn.replace(/CUR_FLOW_PRCS/g,'当前流程设计步骤号')
            }else if(arrprcsIn.indexOf('CUR_USER_NAME')>-1){
                prcsIn=arrprcsIn.replace(/CUR_USER_NAME/g,'当前主办人姓名')
            }else if(arrprcsIn.indexOf('CUR_USER_PRIV')>-1){
                prcsIn=arrprcsIn.replace(/CUR_USER_PRIV/g,'当前主办人角色')
            }else if(arrprcsIn.indexOf('CUR_USER_PRIV_OTHER')>-1){
                prcsIn=arrprcsIn.replace(/CUR_USER_PRIV_OTHER/g,'当前主办人辅助角色')
            }else if(arrprcsIn.indexOf('CUR_USER_DEPT')>-1){
                prcsIn=arrprcsIn.replace(/CUR_USER_DEPT/g,'当前主办人部门')
            }else if(arrprcsIn.indexOf('CUR_USER_DEPT_PARENT')>-1){
                prcsIn=arrprcsIn.replace(/CUR_USER_DEPT_PARENT/g,'当前主办人上级部门')
            }else{
                prcsIn = arrprcsIn;
            }
            return prcsIn;
        }


        $('#conditions').click(function () {//条件生成器


            var arrprcsIn=conditionsDate.prcsIn.split('\n')
             // var arrprcsIn=conditionsDate.prcsIn.split('\r')
            var intoTheConditionPrcsIn='';

            for(var m=0;m<arrprcsIn.length;m++){
                if(arrprcsIn[m]!='') {
                    intoTheConditionPrcsIn += '<tr><td width="20%">' + (m + 1) + '</td>' +
                        '<td width="60%"><span>' + checkCondition(arrprcsIn[m]) + '</span><input type="text" name="ConditionsInput" style="display: none">' +
                        '<input type="hidden" value="' + checkCondition(arrprcsIn[m]) + '"></td>' +
                        '<td><a href="javascript:;" class="theEditor" style="margin-right: 10px;color: #2f8ae3">编辑</a>' +
                        '<a href="javascript:void(0);" class="deletes" style="color: #2f8ae3">删除</a></td></tr>'
                }

            }

            var arrprcsOut=conditionsDate.prcsOut.split('\n');

            // var arrprcsOut=conditionsDate.prcsOut.split('\r');
            // console.log(strprcsOut)
            // console.log(arrprcsOut)
            var transferConditionsprcsOut='';

            for(var q=0;q<arrprcsOut.length;q++){
                if(arrprcsOut[q]!=''){
                   if(arrprcsOut[q].indexOf('"')>=0){
                       arrprcsOut[q] = arrprcsOut[q].replace(/"/g,"'");
                   }

                    transferConditionsprcsOut+= '<tr><td width="20%">' + (q + 1) + '</td>' +
                        '<td width="60%"><span>' + checkCondition(arrprcsOut[q]) + '</span><input type="text" name="ConditionsInput" style="display: none">' +
                        '<input type="hidden" value="' + checkCondition(arrprcsOut[q]) + '"></td>' +
                        '<td><a href="javascript:;" class="theEditor" style="margin-right: 10px;color: #2f8ae3">编辑</a>' +
                        '<a href="javascript:void(0);" class="deletes" style="color: #2f8ae3">删除</a></td></tr>'
                }
            }

            var str='<option value="">请选择</option>'
            if(alertData==undefined){
                $.layerMsg({content:'正在保存表单，即将刷新！',icon:6},function(){
                    location.reload()
                });

            }
            var str2=
                '<option value="[主办人会签意见]">[主办人会签意见]</option>' +
                '<option value="[经办人会签意见]">[经办人会签意见]</option>' +
                '<option value="[公共附件名称]">[公共附件名称]</option>' +
                '<option value="[公共附件个数]">[公共附件个数]</option>' +
                '<option value="[当前步骤号]">[当前步骤号]</option>' +
                '<option value="[当前流程设计步骤号]">[当前流程设计步骤号]</option>' +
                '<option value="[当前主办人姓名]">[当前主办人姓名]</option>' +
                '<option value="[当前主办人角色]">[当前主办人角色]</option>' +
                '<option value="[当前主办人角色_辅助角色]">[当前主办人角色_辅助角色]</option>' +
                '<option value="[当前主办人部门]">[当前主办人部门]</option>' +
                '<option value="[当前主办人上级部门]">[当前主办人上级部门]</option>'
            for (var i = 0; i < alertData.length; i++) {
                str += '<option value="' + alertData[i].name + '">' + alertData[i].title + '</option>'
            }
            var arr = [{'name': '等于', 'val': '='}, {'name': '不等于', 'val': '!='}, {
                'name': '大于',
                'val': '>'
            }, {'name': '小于', 'val': '<'}
                , {'name': '小于等于', 'val': '<='}, {'name': '大于等于', 'val': '>='}, {
                    'name': '包含',
                    'val': 'include'
                }, {'name': '不包含', 'val': 'exclude'}]
            var strone = '';
            for (var i = 0; i < arr.length; i++) {
                strone += '<option value="' + arr[i].val + '">' + arr[i].name + '</option>'
            }

            //<input type="checkbox" lay-filter="typeJudgment" dataType="1" title="字段"/>
            layer.open({
                type:1,
                title:'条件生成器',
                content:'<div class="bottomstepstwoss layui-form" id="bottomstepstwoss">\
            <ul class="candidatesUl" style="display: block;border: none;background:#fff">\
                <li>\
                   <p class="candidatesPone">字段</p> \
                    <div class="dropDownDiv" id="dropDownDiv">\
                        <p class="candidatesPTwo">\
                        <input type="hidden">\
                            <select name="fieldsele" lay-verify="">'+(str+str2)+'</select>\
                        </p>\
                    </div>\
                </li>\
                 <li>\
                   <p class="candidatesPone">条件</p> \
                    <div class="dropDownDiv" style="z-index:99">\
                        <p class="candidatesPTwo">\
                           <select name="conditionss" lay-filter="conditionstwo" lay-verify="">'+strone+'</select>\
                        </p>\
                    </div>\
                </li>\
                <li>\
                   <p class="candidatesPone" id="typepanduan">\
                   <input type="checkbox" lay-filter="typeJudgment" name="typeJudgment2" checked dataType="2" title="值"/>\
                   <input type="checkbox" lay-filter="typeJudgment" name="typeJudgment0" dataType="0" title="数值类型"/>\
                   <input type="checkbox" lay-filter="typeJudgment" name="typeJudgment1" dataType="1" title="表单字段"/></p> \
                        <p class="candidatesPTwo" id="typevalue">\
                            <select name="typeJudgments"  lay-verify="" style="display:none">\
                            <option value="数值">数值</option><option value="日期">日期</option><option value="时间+日期">时间+日期</option></select>\
                            <input type="text" name="typeJudgments" class="typeJudgmentTwo" style="    vertical-align: top;"><span style="text-align: center;font-size: 14px;margin-left: 50px;margin-top: 5px;display: inline-block;">值</span>\
                        </p>\
                          <div class="dropDownDiv" id="dropDownDivs" style="display:none">\
                                       <p class="candidatesPTwo">\
                                      <input type="hidden">\
                                            <select name="fieldsele" lay-verify="">'+(str+str2)+'</select>\
                                        </p>\
                                    </div>\
                                    <p style="font-size: 10pt;color: red;">提示：若条件设置选择复选框控件，则复选框选中条件值需为1，不选中需为0</p>\
                                </li>\
                                <li class="btnzhuanru">\
                                    <a href="javascript:;" class="intoTheConditionBtn" style="margin: 0 20px 0 -52px;" data-add="0">添加转入条件</a>\
                                    <a href="javascript:;" class="intoTheConditionBtn" data-add="1">添加转出条件</a>\
                                </li>\
                                <li>\
                                   <p class="candidatesPone">转入条件列表</p> \
                                   <div class="candidatesPTwo" id="intoTheCondition" style="border: none;margin-bottom: 20px;">\
                                           <table>\
                                                <thead>\
                                                    <tr>\
                                                        <th width="20%">编号</th>\
                                                        <th width="60%">条件描述</th>\
                                                        <th width="20%">操作</th>\
                                                    </tr>\
                                                </thead>\
                                                <tbody>'+intoTheConditionPrcsIn+'</tbody>\
                           </table>\
                   </div>\
                   <p class="candidatesPone">转入条件公式(条件与逻辑运算符之间需空格，如[1] AND [2])</p> \
                    <p class="candidatesPTwo">\
                            <input type="text" name="prcsInSet" value="'+conditionsDate.prcsInSet+'">\
                     </p>\
                      <p class="candidatesPone">不符合条件公式时，给用户的文字描述：</p> \
                    <p class="candidatesPTwo">\
                            <input type="text" name="conditionDesc" value="'+
                function(){

                    if(conditionsDate.conditionDesc==undefined||conditionsDate.conditionDesc==''){
                        return ''
                    }else {
                        if(conditionsDate.conditionDesc.split('\n')[0]==undefined
                        ||conditionsDate.conditionDesc.split('\n')[0]==''){
                            return ''
                        }else {
                            return conditionsDate.conditionDesc.split('\n')[0]
                        }
                    }
                }() + '">\
                            <p style="color: red;font-size: 12px;margin-top: 5px;">合理设定转入条件，可形成流程的条件分支，但数据满足转入条件，才可转入本步骤</p>\
                     </p>\
                </li>\
                <li style="margin-top: 20px;">\
                     <p class="candidatesPone">转出条件列表</p> \
                     <div class="candidatesPTwo" id="transferConditions" style="border: none;margin-bottom: 20px;">\
                         <table>\
                          <thead>\
                                    <tr>\
                                        <th width="20%">编号</th>\
                                         <th width="60%">条件描述</th>\
                                        <th width="20%">操作</th>\
                                    </tr>\
                                </thead>\
                                <tbody>'+transferConditionsprcsOut+'</tbody>\
                         </table>\
                     </div>\
                      <p class="candidatesPone">转出条件公式(条件与逻辑运算符之间需空格，如[1] AND [2])</p> \
                    <p class="candidatesPTwo">\
                            <input type="text" name="prcsOutSet" value="'+conditionsDate.prcsOutSet+'">\
                     </p>\
                      <p class="candidatesPone">不符合条件公式时，给用户的文字描述：</p> \
                    <p class="candidatesPTwo">\
                            <input type="text" name="conditionDesctwo" value="'+function(){

                    if(conditionsDate.conditionDesc==undefined||conditionsDate.conditionDesc=='') {
                        return ''
                    }else {
                        if(conditionsDate.conditionDesc.split('\n')[1]==undefined
                        ||conditionsDate.conditionDesc.split('\n')[1]==''){
                            return ''
                        }else {
                            return conditionsDate.conditionDesc.split('\n')[1]
                        }
                    }
                }()+'">\
                     </p>\
                </li>\
            </ul>\
            </div>',
                area:['800px','600px'],
                btn:['确定','关闭'],
                yes:function (index) {
                    // $('#bottomstepstwoss').find('#intoTheCondition').find('input[type=text]').each(function () {
                    //     $(this).blur();
                    // })
                    // $('#bottomstepstwoss').find('#transferConditions').find('input[type=text]').each(function () {
                    //     $(this).blur();
                    // })

                    var obj={};
                    obj.intoTheCondition={}
                    obj.intoTheCondition.list=''

                    $('#intoTheCondition').find('[type=hidden]').each(function (i,n) {

                        obj.intoTheCondition.list+=$(this).val()+'\n';
                    })
                    obj.intoTheCondition.prcsInSet=$('#bottomstepstwoss').find('[name="prcsInSet"]').val()
                    obj.intoTheCondition.conditionDesc=$('#bottomstepstwoss').find('[name="conditionDesc"]').val()

                    obj.transferConditions={};
                    obj.transferConditions.list='';
                    $('#transferConditions').find('[type=hidden]').each(function (i,n) {
                        // console.log($(this).val())
                        obj.transferConditions.list+=$(this).val()+'\n';
                    })
                    obj.transferConditions.prcsOutSet=$('#bottomstepstwoss').find('[name="prcsOutSet"]').val()
                    obj.transferConditionTwo=$('#bottomstepstwoss').find('[name="conditionDesc"]').val()
                    obj.transferConditions.conditionDesc=$('#bottomstepstwoss').find('[name="conditionDesctwo"]').val()

                   var strobj=JSON.stringify(obj);

                    $('[name="settlementOfCondition"]').val(strobj);
                    $('.setUpThe').removeClass('active')
                    layer.close(index)
                },
                btn2:function () {
                    $('.setUpThe').removeClass('active')
                },
                success:function () {
                    form.render();
                    $('#typevalue').find('select').next().hide();
                    $('.intoTheConditionBtn').click(function () {
                        var strval;
                        var dataType="";
                        if($('#typevalue').css('display')!='none'){
                            if($('#typevalue div').css('display')=='none'){
                                strval=$('input[name="typeJudgments"]').val()
                                dataType='0'
                            }else{
                                strval=$('select[name="typeJudgments"]').val()
                                dataType='0'
                            }
                        }else{
                            strval=$('#dropDownDivs [name="fieldsele"]').next().find('input').val()
                            dataType='1'
                        }

                        var strIng='';
                        var num;
                        var strconditions="'"+$('#dropDownDiv [name="fieldsele"]').next().find('input').val()+"'" +
                            ""+$('[name="conditionss"]').val()+"'"+strval+"'";
                            if($(this).attr('data-add')=='0'){
                                strIng='<tr><td width="20%">'+($('#intoTheCondition table tbody tr').length+1)+'</td>' +
                                    '<td width="60%" dataType="'+dataType+'"><span>'+strconditions+'</span><input type="text" value="'+strconditions+'" name="ConditionsInput" style="display: none">' +
                                    '<input type="hidden" value="'+strconditions+'"></td>' +
                                    '<td><a href="javascript:;" class="theEditor" style="margin-right: 10px;color: #2f8ae3">编辑</a>' +
                                    '<a href="javascript:;" class="deletes" style="color: #2f8ae3">删除</a></td></tr>'
                                $('#intoTheCondition table tbody input[type=hidden]').each(function (i,n) {
                                    if($(this).val()==strconditions){
                                        alert('已有，请不要重复添加');
                                        num=1;
                                        return false;
                                    }
                                })
                                if(num==1){
                                    return;
                                }
                                $('#intoTheCondition table tbody').append(strIng)
                            }else if($(this).attr('data-add')=='1'){
                                strIng='<tr><td width="20%">'+($('#transferConditions table tbody tr').length+1)+'</td>' +
                                    '<td width="60%"><span>'+strconditions+'</span><input type="text" name="ConditionsInput" value="'+strconditions+'" style="display: none">' +
                                    '<input type="hidden" value="'+strconditions+'"></td>' +
                                    '<td><a href="javascript:;" class="theEditor" style="margin-right: 10px;color: #2f8ae3">编辑</a>' +
                                    '<a href="javascript:;" class="deletes" style="color: #2f8ae3">删除</a></td></tr>'
                                $('#transferConditions table tbody input[type=hidden]').each(function (i,n) {
                                    if($(this).val()==strconditions){
                                        alert('已有，请不要重复添加');
                                        num=1;
                                        return false;
                                    }
                                })
                                if(num==1){
                                    return;
                                }
                                $('#transferConditions table tbody').append(strIng)
                            }

                    })

                }
            })


            //条件生成器里下拉
            form.on('select(conditionstwo)', function(data){
                // console.log(data.elem); //得到select原始DOM对象
                // console.log(data.value); //得到被选中的值
                // console.log(data.othis); //得到美化后的DOM对象
                $('[name="typeJudgments"]').val('');;
                $('[name="typeJudgment2"]').next().addClass('layui-form-checked');
                $('[name="typeJudgment0"]').next().removeClass('layui-form-checked');
                $('[name="typeJudgment1"]').next().removeClass('layui-form-checked');
                if(data.value=='='||data.value=='!='){
                    $('#typepanduan').find('div').show();
                }else {
                    $('#typevalue').show();
                    $('#dropDownDivs').hide();
                    $('#typepanduan').find('div').hide();
                    $('#typevalue').find('select').next().hide();
                    $('.typeJudgmentTwo').show();
                    $('.typeJudgmentTwo').next().show();
                }
            });
            form.on('checkbox(typeJudgment)', function(data){
                var dataType = data.elem.getAttribute('dataType'); //是否被选中，true或者false
                if(dataType==0){
                    $('#typevalue').show();
                    $('#dropDownDivs').hide();
                    $('[name="typeJudgment1"]').attr("checked", false);
                    $('[name="typeJudgment2"]').attr("checked", false);
                    form.render();
                    if(data.elem.checked){
                        $('#typevalue').find('select').next().show();
                        $('.typeJudgmentTwo').hide();
                        $('.typeJudgmentTwo').next().hide();

                    }else {
                        $('#typevalue').find('select').next().hide();
                        $('.typeJudgmentTwo').show();
                        $('.typeJudgmentTwo').next().show();
                    }
                }else if (dataType==1){
                    $('[name="typeJudgment0"]').attr("checked", false);
                    $('[name="typeJudgment2"]').attr("checked", false);
                    form.render();
                    if(data.elem.checked){
                        $('#typevalue').hide();
                        $('#dropDownDivs').show();
                    }else{
                        $('#typevalue').show();
                        $('#dropDownDivs').hide();
                    }
                }else{
                    $('[name="typeJudgment1"]').attr("checked", false);
                    $('[name="typeJudgment0"]').attr("checked", false);
                    form.render();
                    $('#typevalue').show();
                    $('#dropDownDivs').hide();
                    if(data.elem.checked){
                        $('#typevalue').find('select').next().hide();
                        $('.typeJudgmentTwo').show();
                        $('.typeJudgmentTwo').next().show();
                    }else {
                        $('#typevalue').find('select').next().show();
                        $('.typeJudgmentTwo').hide();
                        $('.typeJudgmentTwo').next().hide();
                    }

                }
            });

        })

        var newtheTrigger={//新增触发器公功能
            obj:{},
            init:function () {
                var me=this;
                $(document).delegate('.dataCid','click',function () {
                    me.openAlert(this);
                })
            },
            openAlert:function (me) {
                var strUrls,strtitle,obj={};
                if($(me).attr('data-Cid')==0) {
                    strUrls ='/tigger/saveTigger';
                    strtitle='新建触发器';
                    obj.pluginTypes='';
                    obj.sortIds='';
                    obj.namelllss='';
                    obj.pluginWays='';
                    obj.descriptions='';
                    obj.startThe='';
                    obj.id=''
                }else {
                    strUrls='/tigger/updateTigger';
                    strtitle='编辑触发器';


                    obj.pluginTypes = $(me).parent().parent().find('[name="pluginTypes"]').val();
                    obj.plugin = $(me).parent().parent().find('td').eq(3).find('input').val()
                    obj.sortIds = $(me).parent().parent().find('[name="sortIds"]').val();
                    obj.namelllss = $(me).parent().parent().find('[name="namelllss"]').val();
                    obj.pluginWays = $(me).parent().parent().find('[name="pluginWays"]').val();
                    obj.descriptions = $(me).parent().parent().find('[name="descriptions"]').val();
                    obj.startThe = function () {
                        if ($(me).parent().parent().find('[name="startThe"]').is(':checked')) {
                            return 1
                        } else {
                            return 0
                        }
                    }()
                    obj.id = $(me).parent().parent().find('[name="theIncrease"]').val();
                    obj.businessLogicId = $(me).siblings('[name="businessLogicId"]').val()
                    obj.isGlobal = $(me).siblings('[name="isGlobals"]').val()
                }
                layer.open({
                    type:1,
                    title:strtitle,
                    content:'<div id="bottomstepstwoss" class="bottomstepstwoss layui-form" style="height: 380px;">'+
                    '<ul class="candidatesUl" style="display: block;border: none;background:#fff">'+
                       '<li>'+
                        '<input type=hidden id="theIncrease" value="'+obj.id+'">'+
                            '<p class="candidatesPone"><b style="color:red;margin-right: 8px;vertical-align: middle">*</b>触发节点</p> '+
                            '<div class="dropDownDiv" style="z-index:100010">'+
                                '<p class="candidatesPTwo">'+
                                  '<select name="pluginType" lay-verify="" value="'+ obj.pluginTypes+'">'+
                                    /*'<option value="CREATE">新建操作</option>\
                                    <option value="RECEIVE">接收操作</option>\
                                    <option value="SAVE">保存操作</option>'+*/
                                    '<option value="TURN">转交操作</option>'+
                                    /*'<option value="INTRUST">委托操作</option>\*/
                                    '<option value="BACK">退回操作</option>'+
                                '</select>\
                                </p>\
                             </div>\
                        </li>\
                        <li>\
                            <p class="candidatesPone"><b style="color:red;margin-right: 8px;vertical-align: middle">*</b>排序号</p> \
                            <div class="dropDownDiv" style="z-index:99998">\
                                <p class="candidatesPTwo">\
                                   <input type="text" name="sortId" value="'+obj.sortIds+'">\
                                </p>\
                             </div>\
                        </li>\
                        <li>\
                            <p class="candidatesPone"><b style="color:red;margin-right: 8px;vertical-align: middle">*</b>名称</p> \
                            <div class="dropDownDiv" style="z-index:99997">\
                                <p class="candidatesPTwo">\
                                 <input type="text" name="nameTwo" value="'+obj.namelllss+'">\
                                </p>\
                             </div>\
                        </li>\
                          <li>\
                            <p class="candidatesPone">执行插件</p> \
                            <div class="dropDownDiv" style="z-index:100000" id="pluginWaythree">\
                                <p class="candidatesPTwo">\
                                  <select name="plugin"  lay-verify="" value="'+obj.plugin+'">\
                                        <option value="">请选择</option>\
                                    </select>\
                                </p>\
                             </div>\
                        </li>\
                        <li>\
                            <p class="candidatesPone">执行方式</p> \
                            <div class="dropDownDiv" style="z-index:99998">\
                                <p class="candidatesPTwo">\
                                    <select name="pluginWay" value="'+obj.pluginWays+'" lay-verify="">\
                                        <option value="BEFORE_FRONTEND">前台,执行操作前</option>\
                                        <option value="AFTER_FRONTEND">前台,执行操作后</option>\
                                        <option value="BEFORE_BACKEND">后台,执行操作前</option>\
                                        <option value="AFTER_BACKEND">后台,执行操作后</option>\
                                    </select>\
                                </p>\
                             </div>\
                        </li>\
                        <li>\
                            <p class="candidatesPone">业务接口</p> \
                            <div class="dropDownDiv" id="candidatesPoneTwo" style="z-index:99996">\
                                <p class="candidatesPTwo">\
                                    <select name="businessLogicId" value="'+obj.businessLogicId+'" lay-verify="">\
                                        <option value="BEFORE_FRONTEND">请选择</option>\
                                    </select>\
                                </p>\
                             </div>\
                        </li>\
                        <li>\
                            <p class="candidatesPone">触发器描述</p> \
                                <p class="candidatesPTwo" style="border:none;overflow:hidden">\
                                   <textarea name="description" value="'+obj.descriptions+'">'+obj.descriptions+'</textarea><span style="display:inline-block;margin: 19px 0px 0px 10px;text-align:center;color:#3994f7;border-radius:4px;font-size:14px">清空</span>\
                                </p>\
                        </li>\
                        <li>\
                            <p class="candidatesPone">是否启用</p> \
                            <div class="" style="z-index:99995">\
                                <p class="candidatesPTwo" style="border:none">\
                                    <label style="font-size:14px"><input type="radio" name="actived" checked value="1" title="启用"></label>\
                                    <label style="font-size:14px"><input type="radio" name="actived"  value="0" title="禁用"></label>\
                                </p>\
                             </div>\
                        </li>\
                        <li>\
                            <p class="candidatesPone">是否是全局触发器</p> \
                            <div class="dropDownDiv" style="z-index:99995">\
                                <p class="candidatesPTwo" style="border:none">\
                                    <label style="font-size:14px"><input type="radio" name="isGlobal" value="1" title="是"></label>\
                                    <label style="font-size:14px"><input type="radio" name="isGlobal" checked  value="0" title="否"></label>\
                                </p>\
                             </div>\
                        </li>\
                    </ul>\
                </div>',
                    area: ['600px', '500px'],
                    btn: ['确定', '关闭'],
                    yes: function (index) {
                        if ($(me).attr('data-Cid') == 0) {
                            $.post(strUrls, {
                                'pluginType': $('[name="pluginType"]').val(),
                                'sortId': $('[name="sortId"]').val(),
                                'name': $('[name="nameTwo"]').val(),
                                'plugin': $('select[name="plugin"]').val(),
                                'pluginWay': $('[name="pluginWay"]').val(),
                                'description': $('[name="description"]').val(),
                                'actived': $('[name="actived"]:checked').val(),
                                'flowId': flowstr,
                                'flowPrcs': $('[name="prcsId"]').val(),
                                'businessLogicId': $('select[name="businessLogicId"]').val(),
                                'isGlobal': $('[name="isGlobal"]:checked').val()
                            }, function (json) {
                                var num = true;
                                if ($('[name="actived"]:checked').val() == 0) {
                                    num = false;
                                } else {
                                    num = true;
                                }

                                var stringTwo='<tr>' +
                                    '<td>'+$('[name="pluginType"]').next().find('input').val()+'<input type="hidden" value="'+$('[name="pluginType"]').val()+'" name="pluginTypes"></td>' +
                                    '<td>'+$('[name="sortId"]').val()+'<input type="hidden" value="'+$('[name="sortId"]').val()+'" name="sortIds"></td>' +
                                    '<td>'+$('[name="nameTwo"]').val()+'<input type="hidden" value="'+$('[name="nameTwo"]').val()+'" name="namelllss"></td>' +
                                    '<td>'+$('[name="plugin"]').next().find('input').val()+'<input type="hidden" value="'+$('[name="plugin"]').val()+'"></td>' +
                                    '<td>'+$('[name="pluginWay"]').next().find('input').val()+'<input type="hidden" value="'+$('[name="pluginWay"]').val()+'" name="pluginWays"></td>' +
                                    '<td>'+$('[name="description"]').val()+'<input type="hidden" value="'+$('[name="description"]').val()+'" name="descriptions"></td>' +
                                    '<td>' +
                                    '<input type="hidden" name="isGlobals" value="'+$('[name="isGlobal"]:checked').val()+'">' +
                                    '<input type="hidden" name="businessLogicId" value="'+$('[name="businessLogicId"]').val()+'">' +
                                    '<input type="hidden" name="theIncrease" value="'+function(){
                                            if($('[name="isGlobal"]:checked').val()==1){
                                                return json.obj[0].id
                                            }else {
                                                return json.object.id
                                            }
                                    }()+'"><a href="javascript:void(0)" class="dataCid" style="cursor:pointer;margin-right: 5px;color: #2b7fe0" data-Cid="1">编辑</a>' +
                                    '<a href="javascript:void(0)" style="color:#2b7fe0;margin-right: 5px;" data-dele="1">删除</a><label style="font-size: 12px">' +
                                    '<input name="startThe" type="checkbox" '+function () {
                                       if(num) {
                                           return 'checked';
                                       }
                                    }()+'>启用</label></td>' +
                                    '</tr>'
                                $('#thetriggersTwo').append(stringTwo);
                                layer.close(index)
                            }, 'json')
                        } else {
                            $.post(strUrls, {
                                'pluginType': $('[name="pluginType"]').val(),
                                'sortId': $('[name="sortId"]').val(),
                                'name': $('[name="nameTwo"]').val(),
                                'plugin': $('select[name="plugin"]').val(),
                                'pluginWay': $('[name="pluginWay"]').val(),
                                'description': $('[name="description"]').val(),
                                'actived': $('[name="actived"]:checked').val(),
                                'flowId': flowstr,
                                'flowPrcs': $('[name="prcsId"]').val(),
                                'id': $('#theIncrease').val(),
                                'businessLogicId': $('select[name="businessLogicId"]').val(),
                                'isGlobal': $('[name="isGlobal"]:checked').val()
                            }, function (json) {
                                $(me).parent().parent().remove();
                                var num;
                                if($('[name="actived"]:checked').val()==0){
                                    num=false;
                                }else {
                                    num=true;
                                }
                                var stringTwo='<tr>' +
                                    '<td>'+$('[name="pluginType"]').next().find('input').val()+'<input type="hidden" value="'+$('[name="pluginType"]').val()+'" name="pluginTypes"></td>' +
                                    '<td>'+$('[name="sortId"]').val()+'<input type="hidden" value="'+$('[name="sortId"]').val()+'" name="sortIds"></td>' +
                                    '<td>'+$('[name="nameTwo"]').val()+'<input type="hidden" value="'+$('[name="nameTwo"]').val()+'" name="namelllss"></td>' +
                                    '<td>'+$('[name="plugin"]').next().find('input').val()+'<input type="hidden" value="'+$('[name="plugin"]').val()+'"></td>' +
                                    '<td>'+$('[name="pluginWay"]').next().find('input').val()+'<input type="hidden" value="'+$('[name="pluginWay"]').val()+'" name="pluginWays"></td>' +
                                    '<td>'+$('[name="description"]').val()+'<input type="hidden" value="'+$('[name="description"]').val()+'" name="descriptions"></td>' +
                                    '<td>' +
                                    '<input type="hidden" name="isGlobals" value="'+$('[name="isGlobal"]:checked').val()+'">' +
                                    '<input type="hidden" name="businessLogicId" value="'+$('[name="businessLogicId"]').val()+'">' +
                                    '<input type="hidden" name="theIncrease" value="'+$('#theIncrease').val()+'"><a href="javascript:void(0)" class="dataCid" style="cursor:pointer;margin-right: 5px;color: #2b7fe0" data-Cid="1">编辑</a>' +
                                    '<a href="javascript:void(0)" style="color:#2b7fe0;margin-right: 5px;" data-dele="1">删除</a><label style="font-size: 12px">' +
                                    '<input name="startThe" type="checkbox" '+function () {
                                        if(num) {
                                            return 'checked';
                                        }
                                    }()+'>启用</label></td>' +
                                    '</tr>'
                                $('#thetriggersTwo').append(stringTwo);
                                layer.close(index)
                            })
                        }
                    },
                    btn2:function (index) {
                        layer.close(index)
                    },
                    success:function () {
                        $('[name="actived"]').each(function (i,n) {
                            if($(this).val()==obj.startThe){
                                $(this).prop('checked',true);
                                return false;
                            }
                        })


                        $('[name="isGlobal"]').each(function (i,n) {
                            if($(this).val()==obj.isGlobal){
                                $(this).prop('checked',true);
                                return false;
                            }
                        })





                            var stringthree='<option value="">请选择</option>'
                            for(var b=0;b<theTriggers.length;b++){
                                if(theTriggers[b].hid==obj.businessLogicId) {

                                    stringthree += '<option value="' + theTriggers[b].hid + '" selected>' + theTriggers[b].hname + '</option>'
                                }else {
                                    stringthree += '<option value="' + theTriggers[b].hid + '">' + theTriggers[b].hname + '</option>'
                                }
                            }
                            $('#candidatesPoneTwo').find('[name="businessLogicId"]').html(stringthree)





                        var stringchufa='<option value="">请选择</option>'
                        for(var i=0;i<theTriggerchufatwo.length;i++){
                                if(theTriggerchufatwo[i].flowPluginId==obj.plugin){
                                    stringchufa+='<option value="'+theTriggerchufatwo[i].flowPluginId+'" selected>'+theTriggerchufatwo[i].flowPluginName+'</option>'
                                }else {

                                    stringchufa += '<option value="' + theTriggerchufatwo[i].flowPluginId + '">' + theTriggerchufatwo[i].flowPluginName + '</option>'
                                }
                        }
                        $('#pluginWaythree').find('[name="plugin"]').html(stringchufa)

                        $('[name="pluginType"] option').each(function (i,n) {
                            if($(this).val()==obj.pluginTypes){
                                $(this).attr('selected',true)
                            }
                        })

                        $('[name="pluginWay"] option').each(function (i,n) {
                            if($(this).val()==obj.pluginWays){
                                $(this).attr('selected',true)
                            }
                        })



                        form.render()

                    }
                })

            }
        }
        newtheTrigger.init();


        $('#theTrigger').click(function () {
            var str=''
            if(theTrigger!=undefined){
                for(var i=0;i<theTrigger.length;i++){
                    str+='<tr>' +
                            '<td>'+theTrigger[i].pluginTypeName+'<input type="hidden" value="'+theTrigger[i].pluginType+'" name="pluginTypes"></td>' +
                            '<td>'+theTrigger[i].sortId+'<input type="hidden" value="'+theTrigger[i].sortId+'" name="sortIds"></td>' +
                            '<td>'+theTrigger[i].name+'<input type="hidden" value="'+theTrigger[i].name+'" name="namelllss"></td>' +
                            '<td>'+function(){
                            if(theTrigger[i].pluginName==undefined){
                                return ''
                            }else {
                                return theTrigger[i].pluginName
                            }
                        }()+'<input type="hidden" value="'+theTrigger[i].plugin+'"></td>' +
                            '<td>'+theTrigger[i].pluginWayName+'<input type="hidden" value="'+theTrigger[i].pluginWay+'" name="pluginWays"></td>' +
                            '<td>'+theTrigger[i].description+'<input type="hidden" value="'+theTrigger[i].description+'" name="descriptions"></td>' +
                            '<td><input type="hidden" name="businessLogicId" value="'+theTrigger[i].businessLogicId+'"><input type="hidden" name="theIncrease" value="'+theTrigger[i].id+'">' +
                        '<input type="hidden" name="isGlobals" value="'+theTrigger[i].isGlobal+'"><a href="javascript:void(0)" class="dataCid" style="margin-right: 5px;cursor:pointer;color: #2b7fe0" data-Cid="1">编辑</a>' +
                            '<a href="javascript:void(0)" style="color:#2b7fe0;margin-right: 5px;" data-dele="1">删除</a>' +
                        '<label><input name="startThe" type="checkbox" '+function () {
                                if(theTrigger[i].actived==1){
                                    return 'checked'
                                }
                        }()+'>启用</label>' +
                        '</tr>'
                }
            }

            layer.open({
                type:0,
                title:'管理触发器',
                content:'<div class="bottomstepstwoss" style="height: 460px">\
            <ul class="candidatesUl" style="display: block;border: none;background: #fff">\
                <li>\
                     <p class="candidatesPone">管理触发器 <label style="cursor: pointer"  class="newtheTrigger dataCid" data-Cid="0">新建触发器</label></p> \
                     <div class="candidatesPTwo" style="border: none;margin-bottom: 20px;width: 91%">\
                         <table>\
                          <thead>\
                                    <tr>\
                                        <th width="10%">触发节点</th>\
                                        <th width="10%">排序号</th>\
                                        <th width="15%">名称</th>\
                                        <th width="15%">执行插件</th>\
                                        <th width="15%">执行方式</th>\
                                        <th width="15%">触发器描述</th>\
                                        <th width="20%">操作</th>\
                                    </tr>\
                                </thead>\
                                <tbody id="thetriggersTwo">'+str+' </tbody>\
                         </table>\
                     </div>\
                    <p class="candidatesPTwo" style="color: red;font-size: 12px;margin-top: 5px;border: none;">说明：列表中按照 【新建操作】->【接收操作】->【保存操作】->【转交操作】->【委托操作】->【退回操作】 的顺序呈现\
            同时，同一触发节点通过 [排序号] 控制触发顺序</p>\
                </li>\
            </ul>\
            </div>',
                area:['900px','600px'],
                btn:['确定','关闭'],
                yes:function (index) {
                    $('.setUpThe').removeClass('active')
                layer.close(index);

                },
                btn2:function () {
                    $('.setUpThe').removeClass('active')
                }
            })
        })
        $(document).delegate('[data-dele="1"]','click',function () {
            var me=this;
            $.get('/tigger/deleteTigger',{'id':$(this).siblings('[name="theIncrease"]').val()},function (json) {
                $(me).parent().parent().remove()
                alert('删除成功')
            },'json')
        })

        var canWriteField={//字段权限设置
            obj:{},
            init:function () {
                var me=this;
                $(document).delegate('.canWriteFields','click',function () {
                    me.openAlert()
                })
                $(document).delegate('.bottomsteptwos','click',function () {
                    me.bottomsteptwo(this);
                })
                $(document).delegate('.bottomsteptwoss','click',function () {
                    me.bottomsteptwos(this);
                })
            },
            openAlert:function () {
                var str='';
                var arr=[
                    {'standard':'督办工作内容及完成标准','name':'111'},
                    {'standard':'责任部门','name':'111'},
                    {'standard':'	完成时间','name':'111'},
                    {'standard':'督办工作完成情况','name':'111'},
                    {'standard':'验证结果','name':'111'},
                ]
                for(var i=0;i<arr.length;i++){
                    str+='<tr>\
                              <td width="35%">'+arr[i].standard+'</td>\
                              <td width="75%">\
                                      <input type="checkbox" title="保密模式" lay-skin="primary">\
                                       <input type="checkbox" title="只读模式" lay-skin="primary">\
                                      <input type="checkbox" title="删除模式" lay-skin="primary">\
                               </td>\
                        </tr>'
                }
                layer.open({
                    type:1,
                    title:'字段权限设置',
                    content:'<div class="bottomstepstwoss layui-form" style="height: 300px">\
            <ul class="candidatesUl" style="display: block;border: none;padding-left: 7%;background: #fff">\
                <li>\
                 <p class="candidatesPTwo" style="border: none;margin-bottom: 20px;width: 92%;margin-top: 36px;">\
                    <table>\
                                <tbody>'+str+'</tbody>\
                      </table>\
                 </p>\
                </li>\
            </ul></div>',
                    area:['600px','400px'],
                    btn:['确定','关闭'],
                    yes:function () {

                    },
                    success:function () {
                        form.render()
                    }
                })
            },
            bottomsteptwo:function (me) {
                if(alertData==undefined){
                    $.layerMsg({content:'正在保存表单，即将刷新！',icon:6},function(){
                        location.reload()
                    });

                }
                var str='';

                for(var i=0;i<alertData.length;i++){
                        str += '<input type="checkbox" title="' + alertData[i].title + '" value="' + alertData[i].title + '">'
                }

                layer.open({
                    type:1,
                    title:'本步骤可写字段',
                    content:'<div class="bottomstepstwo layui-form" style="margin: 10px ;"><div class="divAllData"><input type="checkbox" title="紧急程度" value="[C@]">' +
                    ''+function () {
                       if(trueFile==1){
                           return '<input type="checkbox" title="流程公共附件" value="[A@]">'
                       }else {
                           return ''
                       }
                    }()+''+str+'' +
                    '<input type="checkbox" title="工作名称/文号" value="[B@]"></div>' +
                    '<div id="checkAll" style="margin-top: 15px;"><span><input type="checkbox" title="全选"></span></div>'+
                    '</div>' ,
                    area:['600px','400px'],
                    btn:['确定','关闭'],
                    resizing: function(layero){
                        layero.find('.bottomstepstwo').css('height',layero.find('.layui-layer-content').height()-30+'px');
                    },
                    yes:function (index) {
                        var strs='';
                        var strTwo='';
                        var obj=$('.bottomstepstwo .divAllData input[type=checkbox]:checked');
                        obj.each(function (i,n) {
                            if(i<obj.length-1){
                                strs+=$(this).val()+','
                            }else {
                                strs+=$(this).val();
                            }
                            strTwo+='<li>('+(i+1)+')'+$(this).next().find('span').text()+'</li>'
                        })
                        $(me).nextAll('input').val(strs);
                        $(me).prev().html(strTwo)
                        layer.close(index)
                    },
                    success:function () {

                        var prcsItemNum=$('[name="prcsItem"]').val();
                        if(prcsItemNum!=''){
                            var prcsItemArrs=prcsItemNum.split(',')
                            var prcsItemArrsTwo=$('.divAllData input[type=checkbox]');
                            for(var i=0;i<prcsItemArrsTwo.length;i++){
                                for(var n=0;n<prcsItemArrs.length;n++){
                                    if($(prcsItemArrsTwo[i]).val()==prcsItemArrs[n]){
                                        $(prcsItemArrsTwo[i]).attr('checked',true)
                                    }else{
                                    }
                                }
                            }
                        }
                        form.render();
                    }
                })

            },
            bottomsteptwos:function (me) {
                if(alertData==undefined){
                    $.layerMsg({content:'正在保存表单，即将刷新！',icon:6},function(){
                        location.reload()
                    });

                }
                var str='';


                for(var i=0;i<alertData.length;i++){
                    if(alertData[i].dataType =='macros'){
                        str += '<input type="checkbox" title="' + alertData[i].title + '" value="' + alertData[i].title + '">'
                    }
                }

                layer.open({
                    type:1,
                    title:'本步骤可写字段',
                    content:'<div class="bottomstepstwo layui-form" style="margin: 10px ;"><div class="divAllData">' +
                    ''+str+'' +
                    '</div>' +
                    '<div id="checkAll" style="margin-top: 15px;"><span><input type="checkbox" title="全选"></span></div>'+
                    '</div>' ,
                    area:['600px','400px'],
                    resizing: function(layero){
                        layero.find('.bottomstepstwo').css('height',layero.find('.layui-layer-content').height()-30+'px');
                    },
                    btn:['确定','关闭'],
                    yes:function (index) {
                        var strs='';
                        var strTwo='';
                        var obj=$('.bottomstepstwo .divAllData input[type=checkbox]:checked');
                        obj.each(function (i,n) {
                            if(i<obj.length-1){
                                strs+=$(this).val()+','
                            }else {
                                strs+=$(this).val();
                            }
                            strTwo+='<li>('+(i+1)+')'+$(this).next().find('span').text()+'</li>'
                        })
                        $(me).nextAll('input').val(strs);
                        $(me).prev().html(strTwo)
                        layer.close(index)
                    },
                    success:function () {
                        var prcsItemNum=$('[name="prcsItemAuto"]').val();
                        if(prcsItemNum!=''){
                            var prcsItemArrs=prcsItemNum.split(',')
                            var prcsItemArrsTwo=$('.divAllData input[type=checkbox]');
                            for(var i=0;i<prcsItemArrsTwo.length;i++){
                                for(var n=0;n<prcsItemArrs.length;n++){
                                    if($(prcsItemArrsTwo[i]).val()==prcsItemArrs[n]){
                                        $(prcsItemArrsTwo[i]).attr('checked',true)
                                    }else{
                                    }
                                }
                            }
                        }
                        form.render('checkbox');
                    }
                })

            }
        }
        canWriteField.init()
        $(document).delegate('.qingkongs','click',function () {
            $(this).siblings('input').val('')
            $(this).siblings('ul').html('')
        })
        $('.QKone').click(function () {
            $(this).siblings('input').val('')
            $(this).parent().prev().html('')
        })








        $('#canWriteField').click(function () {//可写字段

            layer.open({
                type:0,
                title:'编辑可写字段',
                content:' <form class="layui-form"><div class="bottomstepstwoss " >\
            <ul class="candidatesUl" style="display: block;border: none;background:#fff">\
                <li>\
                     <p class="candidatesPone">本步骤可写字段</p> \
                     <div class="candidatesPTwoall" style="margin-bottom: 20px;position:relative">\
                         <ul id="prcsItem"></ul>\
                         <span class="bottomsteptwos" style="position:absolute;top:5px;right:105px;color:#2f8ae3;cursor: pointer;">选择</span>\
                         <a href="javascript:viod(0)" style="position: absolute;top: 30px;right: 105px;color: #2f8ae3;" class="qingkongs">清空</a>\
                          <input type="hidden" name="prcsItem">\
                          <span style="color: #333;width: 90%;line-height: 20px;margin-top: 10px;float: left;font-size: 12px;">说明：如果需要上传公共附件，需要在公共附件中的Office文档详细权限设置中增加新建、编辑、删除、下载、打印等权限</span>\
                     </div>\
                </li>\
                <li>\
                     <p class="candidatesPone" style="display: none;">列表控件模式</p> \
                     <div class="candidatesPTwo" style="display: none;border: none;margin-bottom: 20px;">\
                           <table>\
                                <thead>\
                                    <tr>\
                                        <th width="20%">列表名称</th>\
                                        <th width="60%">列表内容</th>\
                                        <th width="20%">字段权限 </th>\
                                    </tr>\
                                </thead>\
                                <tbody>\
                                </tbody>\
                           </table>\
                   </div>\
                </li>\
                <li>\
                     <p class="candidatesPone">附件上传控件权限（只针对office文档附件，其他格式不控制）</p> \
                     <div class="candidatesPTwo" style="border: none;margin-bottom: 20px;">\
                           <table id="fileUp">\
                                <thead>\
                                    <tr>\
                                        <th width="20%">附件名称</th>\
                                        <th width="80%">控件权限</th>\
                                    </tr>\
                                </thead>\
                                <tbody>\
                                </tbody>\
                           </table>\
                   </div>\
                </li>\
                <li>\
                     <p class="candidatesPone">图片上传控件权限</p> \
                     <div class="candidatesPTwo" style="border: none;margin-bottom: 20px;">\
                           <table id="tupianUp">\
                                <thead>\
                                    <tr>\
                                        <th width="30%">图片名称</th>\
                                        <th width="70%">图片控件权限</th>\
                                    </tr>\
                                </thead>\
                                <tbody>\
                                </tbody>\
                           </table>\
                   </div>\
                </li>\
                 <li>\
                     <p class="candidatesPone activeall" style="margin-bottom:-15px">公文正文权限设置</p> \
                     <div style="margin-top:15px;margin-bottom: 20px;">\
                       <input type="checkbox"  lay-filter="editdocumentEditPriv" title="编辑" '+function () {
                    if(canwritefieldtwo != undefined){
                        if(canwritefieldtwo.documentEditPriv!=undefined){
                            if(canwritefieldtwo.documentEditPriv==0){
                                return ''
                            }else {
                                return 'checked'
                            }
                        }else {
                            return ''
                        }
                    }else{
                        $.layerMsg({content:'正在保存表单，即将刷新',icon:6,time:5000});
                        location.reload();
                    }
                }()+' name="documentEditPriv">\
                     </div>\
                </li>\
                 <li style="display:none">\
                     <div style="margin-top:15px;">\
                      <input type="checkbox" title="上传文件" name="documentEditPrivDetail" value="3001">\
                      <input type="checkbox" title="打开模板" name="documentEditPrivDetail" value="1009">\
                      <input type="checkbox" title="保存" name="documentEditPrivDetail" value="1001">\
                      <input type="checkbox" title="套红" name="documentEditPrivDetail" value="1002">\
                      <input type="checkbox" title="修订" name="documentEditPrivDetail" value="1003">\
                      <input type="checkbox" title="显示标记" name="documentEditPrivDetail" value="1005">\
                     </div>\
                     <div style="margin-top:15px">\
                      <input type="checkbox" title="默认修订" name="documentEditPrivDetail" value="1007">\
                      <input type="checkbox" title="盖章" name="documentEditPrivDetail" value="1008">\
                      <input type="checkbox" title="打印" name="documentEditPrivDetail" value="1010">\
                      <input type="checkbox" title="定稿" name="documentEditPrivDetail" value="3004">\
                      </div>\
                     <div style="margin-top:15px">\
                        <input type="checkbox" title="转PDF版式文件" name="documentEditPrivDetail" value="3005">\
                        <input type="checkbox" title="切换为Word编辑" name="documentEditPrivDetail" value="3006">\
                        <input type="checkbox" title="WORD正文下载" name="documentEditPrivDetail" value="3007">\
                        <input type="checkbox" title="PDF正文下载" name="documentEditPrivDetail" value="3008">\
                    </div>\
                      <div style="margin-top:15px">\
                      <input type="checkbox" title="删除PDF" name="documentEditPrivDetail" value="3009">\
                      </div>\
                </li>\
               <li>\
                     <p class="candidatesPone">允许在不可写情况下自动赋值的宏控件</p> \
                     <div class="candidatesPTwoall" style="margin-bottom: 20px;position:relative">\
                         <ul id="prcsItemAuto"></ul>\
                         <span class="bottomsteptwoss" style="position:absolute;top:6px;right:105px;color:#2f8ae3;cursor: pointer;">选择</span>\
                         <a href="javascript:viod(0)" style="position: absolute;top: 30px;right: 105px;color: #2f8ae3;" class="qingkongs">清空</a>\
                          <input type="hidden" name="prcsItemAuto">\
                     </div>\
                </li>\
                <li>\
                     <p class="candidatesPone activeall" style="margin-bottom:-15px">公共附件中的Office文档详细权限设置</p> \
                     <div style="margin-top:15px">\
                       <input type="checkbox" title="新建权限" name="attachPriv" value="1">\
                       <input type="checkbox" title="编辑权限" name="attachPriv" value="2">\
                        <input type="checkbox" title="删除权限" name="attachPriv" value="3">\
                       <input type="checkbox" title="下载权限" name="attachPriv" value="4">\
                       <input type="checkbox" title="打印权限" name="attachPriv" value="5">\
                     </div>\
                </li>\
                <li>\
                     <p class="candidatesPone activeall" style="margin-bottom:-15px">是否允许本步骤经办人编辑附件</p> \
                     <div>\
                        <label class="canWriteFie"><input type="radio" title="允许" name="attachEditPriv" value="0"></label>\
                        <label class="canWriteFie"><input type="radio" checked="true" title="不允许" name="attachEditPriv" value="1"></label>\
                     </div>\
                </li>\
                <li>\
                     <p class="candidatesPone activeall" style="margin-bottom:-15px">是否允许本步骤办理人在线创建文档</p> \
                     <div>\
                        <label class="canWriteFie"><input type="radio" checked="true" title="允许" name="attachEditPrivOnline" value="0"></label>\
                         <label class="canWriteFie"><input type="radio" title="不允许" name="attachEditPrivOnline" value="1"></label>\
                      </div>\
                 </li>\
                  <li>\
                     <p class="candidatesPone activeall" style="margin-bottom:-15px">宏标记附件上传为图片时展示效果</p> \
                     <div>\
                        <label class="canWriteFie"><input type="radio" checked="true" title="显示图片" name="attachMacroMark" value="0"></label>\
                        <label class="canWriteFie"><input type="radio" title="显示图标和名称" name="attachMacroMark" value="1"></label>\
                     </div>\
                </li>\
                <li>\
                     <p class="candidatesPone activeall" style="margin-bottom:-15px">是否允许本步骤无主办人会签上传、删除附件</p> \
                     <div>\
                        <label class="canWriteFie"><input type="radio" title="否" name="noMainSignerFileYn" value="0"></label>\
                        <label class="canWriteFie"><input type="radio" checked="true" title="是" name="noMainSignerFileYn" value="1"></label>\
                     </div>\
                </li>\
            </ul>\
            </div></form>',
                area:['800px','600px'],
                btn:['确定','关闭'],
                yes:function (index) {
                    var obj={};
                    obj.prcsItem=$('[name="prcsItem"]').val();
                    obj.prcsItemAuto=$('[name="prcsItemAuto"]').val();
                    obj.attachPriv='';
                    $('[name="attachPriv"]:checked').each(function (i,n) {
                        obj.attachPriv+=$(this).val()+','
                    })
                    obj.attachEditPriv=$('[name="attachEditPriv"]:checked').val()
                    obj.attachEditPrivOnline=$('[name="attachEditPrivOnline"]:checked').val()
                    obj.attachMacroMark=$('[name="attachMacroMark"]:checked').val()
                    obj.noMainSignerFileYn=$('[name="noMainSignerFileYn"]:checked').val()
                    if($('[name="documentEditPriv"]').is(':checked')){
                        obj.documentEditPriv=1;
                    }else {
                        obj.documentEditPriv=0;
                    }
                    obj.documentEditPrivDetail='';
                    $('[name="documentEditPrivDetail"]:checked').each(function (i,n) {
                        obj.documentEditPrivDetail+=$(this).val()+','
                    })

                    var str=JSON.stringify(obj)
                    $('.setUpThe').removeClass('active')
                    $('[name="prcsItemTwo"]').val(str);
                    var arrFileUp=[];
                    $('#fileUp tbody tr').each(function (i,n) {
                        var fileObj={};
                        fileObj['FILE_PRIV_'+$(this).find('input[type="hidden"]').val()+'']=[];
                        var fileObjArr=$(this).find('[name="fileuploadXiazai"]:checked');
                        for(var m=0;m<fileObjArr.length;m++){
                            fileObj['FILE_PRIV_'+$(this).find('input[type="hidden"]').val()+''].push(fileObjArr[m].value)
                        }
                        arrFileUp.push(fileObj)
                    })
                    $('[name="fileuploadPriv"]').val(JSON.stringify(arrFileUp));
                    var arrtupianUp=[];

                    $('#tupianUp tbody tr').each(function (i,n) {
                        var tupianObj={};
                        tupianObj['IMG_PRIV_'+$(this).find('input[type="hidden"]').val()+'']=[];
                        var tupianObjArr=$(this).find('[name="imguploadXiazai"]:checked');
                        for(var m=0;m<tupianObjArr.length;m++){
                            tupianObj['IMG_PRIV_'+$(this).find('input[type="hidden"]').val()+''].push(tupianObjArr[m].value)
                        }
                        arrtupianUp.push(tupianObj)
                    })
                    $('[name="imguploadPriv"]').val(JSON.stringify(arrtupianUp));
                    canwritefieldtwo.prcsItem = $('input[name=prcsItem]').val();
                layer.close(index)
                },
                btn2:function () {
                    $('.setUpThe').removeClass('active')
                },
                success:function () {
                    form.render();

                    if(alertData!=undefined){
                        var strshangchuan='';
                        var strfujian=''

                        for(var i=0;i<alertData.length;i++){
                            if(alertData[i].dataType=='imgupload'){
                                strshangchuan += '<tr>' +
                                    '<td>'+alertData[i].title+'<input type="hidden" value="'+alertData[i].name+'"></td>' +
                                    '<td>' +
                                    '<input type="checkbox" title="下载" name="imguploadXiazai" value="3">' +
                                    '<input type="checkbox" title="查阅" name="imguploadXiazai" value="1">' +
                                    '<input type="checkbox" title="删除" name="imguploadXiazai" value="2">' +
                                    
                                    '</td>' +
                                    '</tr>'
                            }
                            if(alertData[i].dataType=='fileupload'){
                                strfujian += '<tr>' +
                                    '<td>'+alertData[i].title+'<input type="hidden" value="'+alertData[i].name+'"></td>' +
                                    '<td>' +
                                    '<input type="checkbox" title="下载" name="fileuploadXiazai" value="4">' +
                                    '<input type="checkbox" title="查阅" name="fileuploadXiazai" value="1">' +
                                    '<input type="checkbox" title="编辑" name="fileuploadXiazai" value="2">' +
                                    '<input type="checkbox" title="删除" name="fileuploadXiazai" value="3">' +

                                    // '<input type="checkbox" title="打印" name="fileuploadXiazai" value="5" style="display: none">' +
                                    '</td>' +
                                    '</tr>'
                            }
                        }
                        $('#tupianUp tbody').html(strshangchuan)
                        $('#fileUp tbody').html(strfujian)

                        var fileUpArr=$('#fileUp tbody tr');
                        if($('[name="fileuploadPriv"]').val()!='') {
                            try
                            {
                                var fileuploadPrivArr = JSON.parse($('[name="fileuploadPriv"]').val())
                                for (var i = 0; i < fileUpArr.length; i++) {
                                    var uploadValue = 'FILE_PRIV_'+$(fileUpArr[i]).find('input[type=hidden]').val();
                                    for (var u = 0; u < fileuploadPrivArr.length; u++) {
                                       if(fileuploadPrivArr[u][uploadValue] != undefined){
                                           var fileUpArrTwo = $(fileUpArr[i]).find('[name="fileuploadXiazai"]');
                                           for (var ml = 0; ml < fileuploadPrivArr[u][uploadValue].length; ml++) {
                                               for(var m = 0; m < fileUpArrTwo.length; m++){
                                                   if (fileUpArrTwo[m].value == fileuploadPrivArr[u][uploadValue][ml]) {
                                                       $(fileUpArrTwo[m]).prop('checked', true)
                                                   }
                                               }
                                           }
                                       }
                                    }
                                }
                            }
                            catch(err)
                            {

                            }

                        }


                        if($('[name="imguploadPriv"]').val()!='') {
                            var fileUpArr = $('#tupianUp tbody tr');
                            try{
                                var fileuploadPrivArr = JSON.parse($('[name="imguploadPriv"]').val())
                                for (var i = 0; i < fileUpArr.length; i++) {
                                    var uploadValue = 'IMG_PRIV_'+$(fileUpArr[i]).find('input[type=hidden]').val();
                                    for (var u = 0; u < fileuploadPrivArr.length; u++) {
                                        if(fileuploadPrivArr[u][uploadValue] != undefined){
                                            var fileUpArrTwo = $(fileUpArr[i]).find('[name="imguploadXiazai"]');
                                            for (var ml = 0; ml < fileuploadPrivArr[u][uploadValue].length; ml++) {
                                                for(var m = 0; m < fileUpArrTwo.length; m++){
                                                    if (fileUpArrTwo[m].value == fileuploadPrivArr[u][uploadValue][ml]) {
                                                        $(fileUpArrTwo[m]).prop('checked', true)
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }catch (err){

                            }


                        }












                        form.render();

                    }











                    form.on('checkbox(editdocumentEditPriv)', function(data){
                        if(data.elem.checked){
                            $(data.elem).parent().parent().next().show()
                        }else {
                            $(data.elem).parent().parent().next().hide()
                        }

                    });

                    if($('[name="documentEditPriv"]').is(':checked')){
                        $('[name="documentEditPriv"]').parent().parent().next().show()
                    }



                    if(canwritefieldtwo==undefined){
                        $.layerMsg({content:'正在保存表单，即将刷新！',icon:6},function(){
                            location.reload()
                        });
                    }
                    inputTheEcho('prcsItem',canwritefieldtwo.prcsItem)
                    ulTheEcho('prcsItem',canwritefieldtwo.prcsItem)
                    inputTheEcho('prcsItemAuto',canwritefieldtwo.prcsItemAuto)
                    ulTheEcho('prcsItemAuto',canwritefieldtwo.prcsItemAuto)
                    radioTheEcho('attachEditPriv',canwritefieldtwo.attachEditPriv)
                    radioTheEcho('attachEditPrivOnline',canwritefieldtwo.attachEditPrivOnline)
                    radioTheEcho('attachMacroMark',canwritefieldtwo.attachMacroMark)
                    radioTheEcho('noMainSignerFileYn',canwritefieldtwo.noMainSignerFileYn)
                    checkboxTheEcho('attachPriv',canwritefieldtwo.attachPriv)
                    checkboxTheEcho('documentEditPrivDetail',canwritefieldtwo.documentEditPrivDetail)



                }
            })

        })
        
        
        
        $('.btnTime').click(function () {
            var me=this;
            layer.open({
                type:0,
                title:'编辑可写字段',
                content:' <form class="layui-form"><div class="bottomstepstwoss " style="height: 150px">\
            <ul class="candidatesUl" style="display: block;border: none;background:#fff">\
                <li>\
                     <p class="candidatesPone activeall" style="margin-bottom:-15px">请选择办理时限类型</p> \
                     <div style="margin-top:15px">\
                       <input type="radio" title="小时" name="timetype" value="hour">\
                       <input type="radio" title="天" name="timetype" value="day">\
                     </div>\
                </li>\
            </ul>\
            </div></form>',
                area:['400px','300px'],
                btn:['确定','关闭'],
                yes:function (index) {
                    $(me).attr('data-type',$('[name="timetype"]:checked').val())
                    $(me).html($('[name="timetype"]:checked').attr('title'))
                    layer.close(index)
                },
                success:function () {
                    form.render();
                }
            })
        })
    });
})
